0
votes

I have 4 Movieclips in timeline.these movieclips have inner animation. they are classically tween in timeline. I have to stop and play these four movieclips at a time by play/pause button. Noted that, I have used the following code for that purposes.

It can stop only one MovieClip which is in the upper layer, and the rest 3 Movieclips can't be stopped by play/ pause button. (I have tried all movie clips are in same instance name and also tried with different instance).

Here is my code:

import flash.events.MouseEvent;


var Playing: Boolean = false;
var lastPosition: Number = 0;

play_btn.addEventListener(MouseEvent.CLICK, onPlayClick);
pause_btn.addEventListener(MouseEvent.CLICK, onPauseClick);


function onPlayClick(event: MouseEvent):void {
    if (Playing == false) {
        Playing = true;
        first_sl.play();
        this.play();
    }
}


function onPauseClick(event: MouseEvent):void {
    Playing = false;
    lastPosition = this.position;
    first_sl.stop();
    this.stop();
}
2
You can stop your MovieClips as any other MovieClip : mc1.stop(); mc2.stop(); mc3.stop() .... . - akmozo
i have tried... it works... but here is a problem is the main timeline can't be stopped by play/pause button as well as inner animation of these MovieClips in the timeline... - shaheen alam

2 Answers

0
votes

You can try like when you are stopping main timeline with stage.stop(); also use mc.stop(); ect. and when u play them use stage.play(); also mc.play();

import flash.events.MouseEvent;


var Playing: Boolean = false;
var lastPosition: Number = 0;

play_btn.addEventListener(MouseEvent.CLICK, onPlayClick);
pause_btn.addEventListener(MouseEvent.CLICK, onPauseClick);


function onPlayClick(event: MouseEvent):void {
    if (Playing == false) {
        Playing = true;
        mc.play();
        mc2.play();// other 2 mc's too
        stage.play();
    }
}


function onPauseClick(event: MouseEvent):void {
    Playing = false;
    lastPosition = this.position;
    mc.stop();
    mc2.stop(); // other mc's
    stage.stop();
}

And if you are using last position for timeline also use it for mc's so it will be sync..
hope this on help tho :)

0
votes

To stop the main timeline you can use stop() or MovieClip(root).stop() and to play it again, you can use play() or MovieClip(root).play() :

var playing: Boolean = false;

btn_play.addEventListener(MouseEvent.CLICK, onPlayClick);
btn_pause.addEventListener(MouseEvent.CLICK, onPauseClick);

function onPlayClick(event: MouseEvent):void
{
    if (!playing) {       
        play();         // you can also use : MovieClip(root).play();   
        mc1.play();
        mc2.play();
        mc3.play();
        mc4.play();
        playing = true;
    }
}

function onPauseClick(event: MouseEvent):void
{
    if (playing) { 
        stop();        // you can also use : MovieClip(root).stop();
        mc1.stop();
        mc2.stop();
        mc3.stop();
        mc4.stop();         
        playing = false;
    }
}

Hope that can help.