Copy link to clipboard
Copied
I have 4 movie clips on the stage that are played by themselves with their own play button. I need to get a separate play button (top right corner on linked files) to play all the separate movie clips in sequential order without messing up their individual playback. I can't find anything on how to write that script so that button currently doesn't work. I'm not sure where to start with the code, any ideas? I'm pretty novice at this so specifics are appreciated.
TESTING multi play btns_9.fla - Google Drive
TESTING multi play btns_9.swf - Google Drive
Here is the current AS for the other 4 movie clips:
var playing:Boolean = false;
function stopAllCounts():void {
Count1.gotoAndStop(1);
Count2.gotoAndStop(1);
Count3.gotoAndStop(1);
Count4.gotoAndStop(1);
}
/*1st movieclip*/
Count1.stop();
function startCount1(event:MouseEvent):void {
var stopped:Boolean = Count1.currentFrame == 1 || Count1.currentFrame == Count1.totalFrames;
stopAllCounts();
if (stopped) {
Count1.gotoAndPlay(1);
}
}
startButton1.addEventListener(MouseEvent.CLICK, startCount1);
/*2nd movieclip*/
Count2.stop();
function startCount2(event:MouseEvent):void {
var stopped:Boolean = Count2.currentFrame == 1 || Count2.currentFrame == Count2.totalFrames;
stopAllCounts();
if (stopped) {
Count2.gotoAndPlay(1);
}
}
startButton2.addEventListener(MouseEvent.CLICK, startCount2);
stop();
/*3nd movieclip*/
Count3.stop();
function startCount3(event:MouseEvent):void {
var stopped:Boolean = Count3.currentFrame == 1 || Count3.currentFrame == Count3.totalFrames;
stopAllCounts();
if (stopped) {
Count3.gotoAndPlay(1);
}
}
startButton3.addEventListener(MouseEvent.CLICK, startCount3);
stop();
/*4th movieclip*/
Count4.stop();
function startCount4(event:MouseEvent):void {
var stopped:Boolean = Count4.currentFrame == 1 || Count4.currentFrame == Count4.totalFrames;
stopAllCounts();
if (stopped) {
Count4.gotoAndPlay(1);
}
}
startButton4.addEventListener(MouseEvent.CLICK, startCount4);
stop();
Hi - Yes, exactly! I ended up using the same code I had but added a 5th movie clip that just has the first frame blank and plays them all in a row (I only added two bars for testing purposes). This seems to have solved the issue. I would appreciate so much if you see any issues with it but it all works as I need it to.
I didn't even think about the instance names. I use this file as a mock up I can post without using any proprietary graphics/audio and "count1" makes more sense in context of my p
...Copy link to clipboard
Copied
Hi.
Here is my suggestion:
animate_cc_as3_play_multiple_movie_clips.zip - Google Drive
Besides the code, I did some small changes to the instance names and the timeline actions of each bar.
AS3 code:
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.events.Event;
var count:uint = 0;
var totalBars:uint = 4;
var buttonPrefix:String = "startButton";
var barPrefix:String = "bar";
var currentBar:MovieClip;
function start():void
{
stage.addEventListener(MouseEvent.CLICK, mouseHandler);
}
function enterFrameHandler(e:Event):void
{
currentBar = this[barPrefix + (count % totalBars)] as MovieClip;
if (currentBar.currentFrame == 1)
currentBar.play();
else if (currentBar.currentFrame == currentBar.totalFrames)
count++;
}
function mouseHandler(e:MouseEvent):void
{
if (e.type == MouseEvent.CLICK)
{
if (e.target is SimpleButton)
{
if (e.target.name.indexOf(buttonPrefix) == 0)
{
stage.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
if (currentBar)
currentBar.gotoAndStop(1);
count = e.target.name.slice(buttonPrefix.length, e.target.name.length);
currentBar = this[barPrefix + count] as MovieClip;
currentBar.play();
}
else if (e.target == playAllButton)
{
if (!stage.hasEventListener(Event.ENTER_FRAME))
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
}
}
start();
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
Thanks JC. It's pretty close!
I need the 4 movie clips to act the same as they did before. So have play/stop/restart for each button and when one button is selected it stops the other mc's and starts the new one selected, on one click. All that functionality has to still work. The code looks so much simpler the way you've written it but I don't recognize how to get back the functionality that worked to put this all together. Any ideas to just leave the other buttons as they were and just get that first play button to play all? Appreciate the help!
Copy link to clipboard
Copied
Hi!
OK. No problem.
Just to get things right... The only difference is that in your case the buttons work as toggles, right? So when you click once, ti plays, twice it stops.
Is that correct? Is there any other difference?
Copy link to clipboard
Copied
Hi - Yes, exactly! I ended up using the same code I had but added a 5th movie clip that just has the first frame blank and plays them all in a row (I only added two bars for testing purposes). This seems to have solved the issue. I would appreciate so much if you see any issues with it but it all works as I need it to.
I didn't even think about the instance names. I use this file as a mock up I can post without using any proprietary graphics/audio and "count1" makes more sense in context of my project. I'll consider that next time I post a testing file
Copy link to clipboard
Copied
That's excellent!
What matters is that you got it working.
Cheers,
JC
Find more inspiration, events, and resources on the new Adobe Community
Explore Now