animate an image
I have a read a few ways to animate an image in AS3 and not sure what is the most efficient way.
I want to load 4 images(in 4 files) in a class. Each image is a different frame of a walking movement of a character. What I want to do is load all the images in the constructor and assign the sprite the current frame to display.
eg sprite=bitmap1 then after some time swap images so
sprite=bitmap2 then after some time swap images so etc
sprite=bitmap3....
Is this the logic you do in AS3?
The code loads 1 image so I can change this to 4 images to load (4 bitmaps and 1 sprite for the current frame?)
private var sp:Sprite=new Sprite();
public function ClassImg2(myimg:String,xx:int,yy:int) {
img1=myimg;
myx=xx;
myy=yy;
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(new URLRequest(img1));
}
private function imageLoaded(event:Event):void
{
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
sp.addChild(image);
sp.x = myx;
sp.y = myy;
addChild(sp);