Copy link to clipboard
Copied
Hi - I have two issues I'm trying to solve:
1. I have 4 movie clips on the stage that are played by themselves with their own play button. When selected each play button starts/stops/restarts the movie clip as intended. However, if another play button is selected I'd like the 1st movie clip to stop and the new movie clip to start playing immediately on one click. Right now everything is functioning properly except that it takes two clicks for the 1st movie clip to stop and the 2nd one to start playing. Any ideas?
2. I need to get the larger play button in top right corner to play all the movie clips in sequential order. 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 help is appreciated.
TESTING multi play btns_8.fla - Google Drive
TESTING multi play btns_8.swf - Google Drive
Here's AS 3.0 on main timeline:
var playing:Boolean = false;
/*large button plays all movieclips in a row*/
/*1st movieclip*/
Count1.stop();
function startCount1(event:MouseEvent):void
{
if(Count1.currentFrame == Count1.totalFrames) {
playing = false;
}
if(playing){
Count1.gotoAndStop(1);
} else {
Count2.gotoAndStop(1);
Count3.gotoAndStop(1);
Count4.gotoAndStop(1);
Count1.gotoAndPlay(1);
}
playing = !playing;
}
startButton1.addEventListener(MouseEvent.CLICK, startCount1);
/*2nd movieclip*/
Count2.stop();
function startCount2(event:MouseEvent):void
{
if(Count2.currentFrame == Count2.totalFrames) {
playing = false;
}
if(playing){
Count2.gotoAndStop(1);
} else {
Count1.gotoAndStop(1);
Count3.gotoAndStop(1);
Count4.gotoAndStop(1);
Count2.gotoAndPlay(1);
}
playing = !playing;
}
startButton2.addEventListener(MouseEvent.CLICK, startCount2);
stop();
/*3nd movieclip*/
Count3.stop();
function startCount3(event:MouseEvent):void
{
if(Count3.currentFrame == Count3.totalFrames) {
playing = false;
}
if(playing){
Count3.gotoAndStop(1);
} else {
Count1.gotoAndStop(1);
Count2.gotoAndStop(1);
Count4.gotoAndStop(1);
Count3.gotoAndPlay(1);
}
playing = !playing;
}
startButton3.addEventListener(MouseEvent.CLICK, startCount3);
stop();
/*4th movieclip*/
Count4.stop();
function startCount4(event:MouseEvent):void
{
if(Count4.currentFrame == Count4.totalFrames) {
playing = false;
}
if(playing){
Count4.gotoAndStop(1);
} else {
Count1.gotoAndStop(1);
Count2.gotoAndStop(1);
Count3.gotoAndStop(1);
Count4.gotoAndPlay(1);
}
playing = !playing;
}
startButton4.addEventListener(MouseEvent.CLICK, startCount4);
stop();
You could simplify that code so much by using a shared stop all movieclips function that all the event handlers and initialization called.
function stopAllCounts():void {
Count1.gotoAndStop(1);
Count2.gotoAndStop(1);
Count3.gotoAndStop(1);
Count4.gotoAndStop(1);
}
And don't use a common Boolean for your event handler functions. That's bonkers.
So something like...
function startCount1(event:MouseEvent):void {
var stopped:Boolean = Count1.currentFrame == 1 || Count1.currentFrame ==
...Copy link to clipboard
Copied
You could simplify that code so much by using a shared stop all movieclips function that all the event handlers and initialization called.
function stopAllCounts():void {
Count1.gotoAndStop(1);
Count2.gotoAndStop(1);
Count3.gotoAndStop(1);
Count4.gotoAndStop(1);
}
And don't use a common Boolean for your event handler functions. That's bonkers.
So something like...
function startCount1(event:MouseEvent):void {
var stopped:Boolean = Count1.currentFrame == 1 || Count1.currentFrame == Count1.totalFrames;
stopAllCounts();
if (stopped) {
Count1.gotoAndPlay(1);
}
}
etc...
You might be able to just use "Count1.play()" in the event handler instead of gotoAndPlay. I don't recall whether that would work.
Copy link to clipboard
Copied
Thanks, I'm not clear how this resolves the issue of the double-click or the 2nd issue of the larger button to play all the movie clips sequentially? It sounds like you were giving me some advice on cleaning up the code, thanks I definitely appreciate that but I don't totally understand how to incorporate it and what to delete or in what order. I don't see any code that indicates what play button plays "Count1" movie clip? Sorry your answer may be a bit too advanced for my code skills, which you've pointed out so kindly. I'd love to learn how to do this correctly, and more efficiently, if you could be a little more specific on how to correct it.
Copy link to clipboard
Copied
I'm going to guess that it took two clicks to play because your code is a logical mishmash. Why not try what I've suggested and see if that fixes it? THEN you can try tackling the second issue.
Copy link to clipboard
Copied
Again, I'm all for cleaning this up I know that can definitely help things work properly. As I mentioned I wasn't clear HOW to incorporate your suggestions. After some trial and error I think this was what you were suggesting? The double click is no longer an issue so that's awesome! Any suggestions for the larger play button? If you can be specific it is really appreciated.
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();