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.
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]
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 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.
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.
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…
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);
}
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…
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);
}