Search code examples
apache-flexflash-builderspriteflexbuildermovieclip

Flex AS3 asynchronous sprite (MovieClip) animation


I'm using starling framework under flex AS3 project. I've Sprite which named Bird and it use Altas for animation.

My problem is, there is two bird in my screen and both of them flaps at the same time. I want to flap asynchronous.

How can I do this, can I give a start frame number each of them ? Thanks..

public class Bird extends Sprite
{
    private var bird_mc:MovieClip;

    public function Bird(startFrame:Number = 0)
    {
        super();
        this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
    }

    private function onAddedToStage(event:Event):void
    {
        this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        createBird_mc();
    }

    private function createBird_mc():void
    {
        bird_mc = new MovieClip(Assets.getAtlas().getTextures("Bird_"), 16);
        bird_mc.x = Math.ceil(-bird_mc.width/2);
        bird_mc.y = Math.ceil(-bird_mc.height/2);
        starling.core.Starling.juggler.add(bird_mc);
        this.addChild(bird_mc);
    }
}

Solution

  • the solution is setting activeframe before add to stage.