I'm trying to do a class that holds a bunch of MovieClips inside. Than I call playAnimation("idle"), than it animate the idle animation. I haven't thought about a class to extends from, so I made this way:
- I create all my MovieClips
public static var appearing:MovieClip; public static var loop:MovieClip; public static var exploding:MovieClip; public function drawAnimations():void { var texture:Texture = Assets.getTexture("SpriteSheet"); var xml:XML = XML(new SpriteSheetXML()); var textureAtlas:TextureAtlas = new TextureAtlas(texture, xml); var frames:Vector.<Texture> = textureAtlas.getTextures("Appearing"); appearing = new MovieClip(frames, 24); appearing.addEventListener(Event.COMPLETE, gotoLoop); frames = textureAtlas.getTextures("Loop"); loop = new MovieClip(frames, 24); frames = textureAtlas.getTextures("Exploding"); exploding = new MovieClip(frames, 24); exploding.addEventListener(Event.COMPLETE, remove); }
- Than I implement IAnimatable, create a variable named currentAnimation and override advanceTime method.
private var _currentAnimation:MovieClip; public function advanceTime(passedTime:Number):void { if(currentAnimation) currentAnimation.advanceTime(passedTime); }
- After all that, I made a get/set function for currentAnimation. All I have to do then is to call playAnimation(name:String), which sets the new animation.
public function get currentAnimation():MovieClip { return _currentAnimation; } public function set currentAnimation(value:MovieClip):void { if(currentAnimation) removeChild(currentAnimation); _currentAnimation = value; if(currentAnimation == null) return; addChild(currentAnimation); currentAnimation.play(); }
If I'm not doing anything wrong, it should be working. Im my case, occurs the following:
- I play appering movieclip. It plays 'til the end, where an Event.COMPLETE is dispathing.
- In the Event.COMPLETE method, I set the currentAnimation to loop.
public function gotoLoop(event:Event):void { currentAnimation = loop; }
Here starts my problem: the event is dispatched, it goes inside the function, set the animation but it don't play. It keeps displaying the last frame of "appearing" animation. In set method, it changed to the new animation. But if I trace the currentAnimation outside the set method, it still giving me "appearing" animation, as it haven't changed inside the function. Anyone knows where I'm mistaken?
Another 'bug' is the exploding animation is loop = false. In its Event.COMPLETE method, I remove the currentAnimation but the last frame is still rendering. Is that normal?
public function remove(event:Event):void { currentAnimation = null; }
Thank to all.