views:

89

answers:

1

i've been studying and using actionscript exclusively for too long, that i don't even know how to import a regular image into Flash and create a ready-made sprite that i can use in my APIs.

what are the steps to create a sprite from an image asset in the library?

+2  A: 

Firstly, the Flash IDE does not let you create "Sprites". You can only make MovieClips, Buttons (SimpleButtons), and Graphics.

First make sure you have your image in the library. Either drag the image into the library panel from your file explorer, or import it via File > Import > Import to Library.

Once you have the image in the library, you have a few options for using it.

1. BitmapData Object

You can use the image as a BitmapData object. Right click the image in the library and click Properties. Check Export for ActionScript. Leave the Base class as is, but give it a classname of your choosing (I use a classname of TestImage in my example below). Then you can add that BitmapData to the stage like this:

var imageData:TestImage = new TestImage(80, 80);
var image:Bitmap = new Bitmap(imageData);
addChild(image);

2. MovieClip wrapper

My preferred way is to wrap the image in a MovieClip, then add the MovieClip to the stage. To do this you can drag your image onto the stage, make sure it is selected and choose Modify > Convert to symbol (F8 on PC). When the convert to symbol window pops up make sure you have the advanced options shown, and Type is set to MovieClip. Click Export for ActionScript, and give is a class name (I use a classname of TestMC in my example below). You can then delete the MovieClip instance off the stage. You can add the MovieClip to the stage like this:

var image:MovieClip = new TestMC;
addChild(image);

Hope this all makes sense.

TandemAdam
yes makes sense. with exporting bitmap data to actionscript, it's easy to create a sprite using the image with graphics.beginBitmapFill(). thanks.
TheDarkInI1978