Dirty Bird Design
Dirty Bird Design

Reputation: 5533

Play movie clip, have it wait until end of main movie then restart

I have a flash banner that includes a movie clip of the logo being animated. I want the logo animation to only run at the beginning of the main "movie". Currently I have to find the length of the entire movie (for ex. 500 frames) then put a key frame in at the 500th frame of the logo movie clip. I know there has to be a correct way to do this...Do I add a frame name at the end of the main timeline and somehow in AS in the logo movie clip say "when you reach X goToAndPlay(1);"?

Upvotes: 0

Views: 723

Answers (1)

Jakub Slaby
Jakub Slaby

Reputation: 331

Well, you can't simply do a "when you do this, do that".

There are two ways that come to my mind right now. First the (more) proper one is to add an dispatchEvent( new Event(__EVENT_TYPE__)); to the frame you want to stop on and than add a listener to the movieclip like:

mc1.addEventListener(Event.__EVENT_TYPE__, stopPlayback);
function stopPlayback( e:Event ):void{
   mc1.stop();
   mc1.removeEventListener(Event.__EVENT_TYPE__, stopPlayback);
}

so that when the event is dispatched you will stop playback. You can use for example an Event.COMPLETE or maybe create a custom event.

The second way is to add a Event.ENTER_FRAME event listener than check if we are back to the first frame and if we have looped go back to the last one and stop, remove the event listener and done. Also we need to store somewhere the last frame we were on so that we know to witch we need to get back.

mc1.addEventListener(Event.ENTER_FRAME, onEF);
var lastFrame:int = 0;
function onEF( e:Event ):void{
    if(mc1.currentFrame == 1){
        mc1.removeEventListener(Event.ENTER_FRAME, onEF);
        mc1.gotoAndStop(lastFrame);
    }
    lastFrame = mc1.currentFrame;
}

use the second one only if you cant add a event dispatch to the movie clip (or a simple stop() call ;) )

Hope it helps

Cheers.

Upvotes: 1

Related Questions