Harsha Venkataramu
Harsha Venkataramu

Reputation: 2914

Listen to the end of tick event easelJS/createJS/movieclip class

I have created a simple animation using flash and exported it as a createJS animation(HTML5) . When I went through the source code , I see

function handleComplete() {
    exportRoot = new lib.stage_01();

    stage = new createjs.Stage(canvas);
    stage.addChild(exportRoot);
    stage.update();

    createjs.Ticker.setFPS(25);
    createjs.Ticker.addEventListener("tick", stage);
}

I am guessing that the tick event is subscribed to , that it updates the canvas every particular duration of time.

My Question is , is it possible to detect when an animation has ended. Basically , I need to invoke a method after the animation ends. And no, I am not using a spritesheet for this purpose , if that helps :-)

Thanks guys.

Upvotes: 0

Views: 1827

Answers (2)

Benjamin Winiarczyk
Benjamin Winiarczyk

Reputation: 1

I need to do this all the time. The method I use is to actually add some code into the timeline of the MovieClip in the Flash Actions panel. For example, I will add:

this.is_playing=false;
this.stop();

And set myMovieClip.is_paying to true when I start the animations, then listen for myMovieClip.is_playing to become false in my game update loop.

gameUpdateLoop = function(){
    if(!myMovieClip.is_playing){
        //do something
    }
}
myMovieClip.is_paying = true;
myMovieClip.gotoAndPlay("jump");

Another way... You can also add your own callback to the MovieClip in your Javascript such as:

myMovieClip.callback = someFunction;
myMovie.gotoAndPlay("jump");

Then in the Flash MovieClip timeline, at the end of the jump animation, add the code in the Flash Actions panel:

this.callback();
this.stop();

Of course, you probably need to build on that to be useful but I hope that helps.

Upvotes: 0

Harsha Venkataramu
Harsha Venkataramu

Reputation: 2914

I made a work around for this.

Unfortunately , there is no event which you can fire when the animation ends in a movieclip class viz, there is no onAnimationEnd as in the BITMAP ANIMATION CLASS

I modified my movieclip class to call a method on a particular frame(Useful when there is no dynamically changing content,so that I can know the number of frames I have).

Upvotes: 1

Related Questions