February 01, 2006
ActionScript 3 Klondike Solitaire Sample Application
I've made a few changes to my solitaire game, and I'm proud to say it's showcased on labs! Here's a few of the migration issues I've had:
- Void is now void - This was a minor but very welcome change. A simple find/replace is all you need.
- [Embed(source="someImage.jpg")] broken? - No, this still works. The problem is that the Embed instructs the compiler to create a class that extends SkinSprite or SkinBitmap, and by default these are not included in ActionScript-only projects in FlexBuilder. The solution is to add the framework.swc to the build path, like this:
- Open the project properties and select ActionScript Build Path and then the Libraries tab.
- Click the Add SWC button and use "${FRAMEWORKS}\framework.swc" as the location.
- Event constants no longer have their own "Type" classes for the constants. That is, "EventType.OPEN" is now "Event.OPEN"
These are the main things that I ran into. Of course, there are other migration issues from alpha 1 to beta 1, and I highly recommend you read the release notes as well.
All that being said, you can play the updated game here (requires Flash Player Alpha 3)

Comments
I still can't get the Embed syntax to work - can you illustrate how it works nows with a clear example?
Posted by: Jon B at February 1, 2006 10:20 PM
Did you add the framework.swc to the build path in FlexBuilder? Your code should look something like this (untested, so maybe a syntax error or two, but you get the idea):
package
{
import flash.display.Sprite;
public class Example extends Sprite
{
[Embed(source="someImage.jpg")]
public var SomeImage : Class;
public function Example() {
// Create the image
var s:Sprite = new SomeImage();
// Display the image by adding it to the display list
addChild( s );
}
}
}
Posted by: darron at February 1, 2006 10:35 PM
TypeError: Error #1034: Type Coercion failed: cannot convert Example_SomeImage@8dffac6 to flash.display.Sprite
at Example$iinit()
Posted by: magicwind at February 8, 2006 03:13 AM
@magicwind - When you embed an image as a .swf file, use the Sprite class to add it to the display list. When you embed it as a regular image file (like .jpg), use Bitmap instead. Updated code example:
package
{
import flash.display.Sprite;
import flash.display.Bitmap;
public class Example extends Sprite
{
[Embed(source="someImage.jpg")]
private var SomeImage : Class;
[Embed(source="someImage.swf")]
private var SomeSwf: Class;
public function Example() {
// Create a bitmap from the .jpg
var b:Bitmap = new SomeImage();
addChild( b );
// Create a sprite from the .swf
var s:Sprite = new SomeSwf();
addChild( s );
}
}
}
Posted by: darron at February 8, 2006 08:39 AM