# Playing one movieclip at a time

**URL:** https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329
**Category:** Uncategorized
**Created:** [August 13, 2004, 3:11pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329 "2004-08-13T15:11:42Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sqladmin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sqladmin/32/125_2.png) [@sqladmin](https://forum.kirupa.com/u/sqladmin)
#### Post date: [August 13, 2004, 3:11pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/1 "2004-08-13T15:11:42Z")

</div>

i have a site, and as usual there are various buttons, and when a  
button is clicked an event action occurs. typically running some kind  
of movie clip i have placed on the stage…

my question is…  
how would i setup the buttons to play one at a time. i mean. if i have  
3 buttons (b1, b2, b3) and lets say b2 was clicked, and that mc was already playing… but the user goes to click b3 instead. how would i script the one mc to close out, and tell flash to play b3’s action? i would like all the buttons to behave in this fashion. if one is running, then upon clicking another button it’s actions would detect another mc was running, and simply close it out before running its own actions.

by the way… each button has an associated mc. for example:  
b1 runs b1mc, b2 runs b2mc, b3 runs b3mc. thought this would be useful.

i’m thinking some kind of if/else statement built within the button action would do the trick. for example if b2 was clicked, then the user clicks  
on b3.

if b2mc\_instance playhead = (frame)  
then send playhead to nextframe //close out the current mc  
else b3mc\_instance.play(2) //runs the b3’s associated mc.

i’m trying to make some thing like this, but my programming skills lacking.

any advice with this would be helpful.

thanks

---

<div class="post-metadata">

### Author: ![bwh2](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bwh2](https://forum.kirupa.com/u/bwh2)
#### Post date: [August 13, 2004, 5:04pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/2 "2004-08-13T17:04:04Z")

</div>

you could setup a variable in the main timeline named nowplaying=0;  
then for each button(button 1 is this example):[AS]on(release){  
if(\_root.nowplaying!=1){  
tellTarget(“b”+\_root.nowplaying+“mc”){  
gotoAndStop(1); // frame one would be empty  
}  
}  
\_root.nowplaying=1; // button 1 is clicked  
tellTarget(“b”+\_root.nowplaying+“mc”){  
gotoAndPlay(2); // frame 2 is animation  
}  
}[/AS]

---

<div class="post-metadata">

### Author: ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)
#### Post date: [August 13, 2004, 5:26pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/3 "2004-08-13T17:26:41Z")

</div>

If you want to code on the timeline, you could just type  
num = 4;  
for (i=1; i\<num; i++) {  
this[“b”+i+“mc”].stop();  
//this[“b”+i+“mc”].\_visible = false  
this[“b”+i].ivar = i;  
this[“b”+i].onPress = cont;  
}  
function cont() {  
for (i=1; i\<num; i++) {  
this.\_parent[“b”+i+“mc”].stop();  
//this.\_parent[“b”+i+“mc”].\_visible = false;  
}  
this.\_parent[“b”+this.ivar+“mc”].play();  
//this.\_parent[“b”+this.ivar+“mc”].\_visible = true;  
}

i`ve included option to make invisible

---

<div class="post-metadata">

### Author: ![sqladmin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sqladmin/32/125_2.png) [@sqladmin](https://forum.kirupa.com/u/sqladmin)
#### Post date: [August 13, 2004, 11:35pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/4 "2004-08-13T23:35:56Z")

</div>

i am currently trying them out.

thanks again.

- sqladmin

---

<div class="post-metadata">

### Author: ![sqladmin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sqladmin/32/125_2.png) [@sqladmin](https://forum.kirupa.com/u/sqladmin)
#### Post date: [August 13, 2004, 11:52pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/5 "2004-08-13T23:52:38Z")

</div>

i’ve also received useful information from another poster… and it is pretty much what i’m trying to do.

could some one elaborate on this alittle? i tried some thing out with this, but was unsuccessful.

if (variable == true)

…play this other movie clip instead… then go on to play the intended movie clip

else play the intended movie clip

based on this example i did the following: ‘forgive me if it is all messed up, i’m still pretty new at this…’ by the way this is for the button 2 action.

on (release){  
if (\_root.b3mc == true)  
\_root.b3mc.gotoAndPlay(49);  
else  
\_root.b2mc.play(2);  
}

when i checked the syntax it was fine, but when running live it didn’t work.

---

<div class="post-metadata">

### Author: ![bwh2](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bwh2](https://forum.kirupa.com/u/bwh2)
#### Post date: [August 14, 2004, 5:04am UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/6 "2004-08-14T05:04:58Z")

</div>

well, you’re trying to setup \_root.b3mc as a variable, but it’s really an instance name. what they’re getting at is (this is button3 example):[AS]on(release){  
if(\_root.playingclip==1){ // playingclip is the variable, the number is which mc is playing  
\_root.b1mc.gotoAndPlay(49); // frame 49 is the end of animation for b1mc  
}  
elseif(playingclip==2){  
\_root.b2mc.gotoAndPlay(49); // frame 49 is the end of animation for b2mc  
}  
\_root.b3mc.gotoAndPlay(2); // play b3mc regardless of what the old clip was  
\_root.playingclip==3; // the new playingclip is 3  
}[/AS]they were just doing the longhand version of what i had posted earlier. there’s many ways to set this up. i made mine earlier because i thought it would be easy to add other clips into the mix.

stringy’s is the same way - easy to add other buttons and mc’s. the above version would make it harder to make additions because you would have to go into every button and add if statements for each addition.

---

<div class="post-metadata">

### Author: ![NovemberRain](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@NovemberRain](https://forum.kirupa.com/u/NovemberRain)
#### Post date: [August 14, 2004, 12:23pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/7 "2004-08-14T12:23:59Z")

</div>

Hey i don’t think that has much more complication regarding this matter… this is the code i’ve writtenf or the same .pls check the attachment also…

```auto
 function intStart (){ //To collect the movieclip on the stage
 for (i=1; i<4; i++){
  _root["b"+i+"mc"].stop();
 }
}
intStart(); //Call the function to Stop at the initial time
function RestoreHeader (mc1, mc2, mc3){ //The fist mc starts and play and rest of them restore to frame 1
 mc1.play();
 mc2.gotoAndStop(1);
 mc3.gotoAndStop(1);
}
/:b1.onRelease = function (){
 /:RestoreHeader (/:b1mc, /:b2mc, /:b3mc);
}
//--------------
/:b2.onPress = function (){
/:RestoreHeader (/:b2mc, /:b1mc, /:b3mc);
}
//------------------
/:b3.onPress = function (){
/:RestoreHeader (/:b3mc, /:b1mc, /:b2mc);
}
 

```

---

<div class="post-metadata">

### Author: ![NovemberRain](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@NovemberRain](https://forum.kirupa.com/u/NovemberRain)
#### Post date: [August 14, 2004, 12:24pm UTC](https://forum.kirupa.com/t/playing-one-movieclip-at-a-time/119329/8 "2004-08-14T12:24:50Z")

</div>

Hey i don’t think that has much more complication regarding this matter… this is the code i’ve writtenf or the same .pls check the attachment also…

```auto
 function intStart (){ //To collect the movieclip on the stage
for (i=1; i<4; i++){
_root["b"+i+"mc"].stop();
}
}
intStart(); //Call the function to Stop at the initial time
function RestoreHeader (mc1, mc2, mc3){ //The fist mc starts and play and rest of them restore to frame 1
mc1.play();
mc2.gotoAndStop(1);
mc3.gotoAndStop(1);
}
/:b1.onRelease = function (){
/:RestoreHeader (/:b1mc, /:b2mc, /:b3mc);
}
//--------------
/:b2.onPress = function (){
/:RestoreHeader (/:b2mc, /:b1mc, /:b3mc);
}
//------------------
/:b3.onPress = function (){
/:RestoreHeader (/:b3mc, /:b1mc, /:b2mc);
}

```
