Pages

Wednesday, 24 August 2011

Embedding a sprite sheet with ActionScript

You can embed images in ActionScript through the use of the Embed metadata tag. (Read Embedding metadata with Flash for more information.) Once they're embedded, you can create an instance of the class and attach it to the display list, as in ActionScriptBlittingPart1.as.

ActionScriptBlittingPart1.as (Example 1)
------------------------------------------------------------------
package
{ import flash.display.Sprite;
[SWF(width=480, height=320, frameRate=24, backgroundColor=0xE2E2E2)]
public class ActionScriptBlittingPart1 extends Sprite
{
public function ActionScriptBlittingPart1()
{
addChild(new BrownCollector());
}
[Embed(source="spritesheets/browncollector.png")]
public var BrownCollector:Class;
}
}
---------------------------------------------------------------------
To run the first example, follow these steps:
In the Package Explorer, right-click ActionScriptBlittingPart1.as and select Run Application.
When your browser opens, you should see the entire PNG image from browncollector.png with all the tiles (Example 1).
Close the browser window.

0 comments:

Post a Comment