Skip to main content
May 13, 2008
Question

how to disable other buttons when a button clicked

  • May 13, 2008
  • 4 replies
  • 785 views
I built an app that has 5 buttons that each can play a movieclip. How do I prevent someone playing a second or third... movieclip after one has begun to play?

I have played with the enable property but I don't seem to be able to get it right. The buttons are on the parent stage, not in the movieclip. Their instance names are mycase1_btn, mycase2_btn, mycase3_btn, mycase4_btn, mycase5_btn.
This topic has been closed for replies.

4 replies

Ned Murphy
Legend
May 15, 2008
You're welcome. There's plenty left to learn, so take your time and have fun with it.
May 15, 2008
Thank you very much!! I obviously am new to all but the simplest Actionscript. I learned that functions go on frames etc.

My app buttons work correctly now.
Ned Murphy
Legend
May 13, 2008
The function would go in the timeline that has the buttons, not the same layer, just the same timeline where the buttons exist.

The on(release)... code I provided above would be attached to the buttons. To do that, you click on the button itself on the stage, and then enter that code in the actions panel. An alternative that could go where you put the function code is using...

mycase1_btn.onRelease = function(){

// start the movieclip.... whatever you do for that

// disable the buttons
enableBtns(false);

}

The latter may be preferred because it is more readily visible when hunting things down.

The last line... _parent.enableBtns(true);
could be placed in the last frame of the movieclip that is playing (or whatever else might be detecting the end of the movieclip).
May 14, 2008
I appreciate the help.

I put this code on the mycase3_btn button

function enableBtns(truefalse){
for(i=1; i<6; i++){
this["mycase"+i+"_btn"].enabled = truefalse;
}

// disable the buttons
enableBtns(false);

}
}

on(release)
{
MCCase3b.play();
}

Also I have this code on the last frame on the actions layer of the movieclip.

_parent.enableBtns(true);
gotoAndStop(1);

I tested the app and got this error message referring to the last frame of the actions layer on the movieclip.
Description =1120: Access of undefined property _parent.
Source =_parent.enableBtns(true);

I probably have the syntax off, but that is what I have. What do you suggest?

Ned Murphy
Legend
May 14, 2008
That function should go on the timeline, not on the button, and it should not include the call to itself in the function.... that will go on forever so the movieclip might enable the buttons for a micrsecond, but the function will still be running telling all the buttons to be disabled.

The code on the button should be..

on(release)
{
MCCase3b.play();
enableBtns(false);
}

I can't be sure what the movieclip's _parent issue is since that's a legit call, provided the movieclip is a child of the movie that holds the enableBtns function.
Ned Murphy
Legend
May 13, 2008
I don't know if you missed seeing my reply to your first posting of this, or tried it and couldn't get it to work, but it will work (it's written for your code). If you have a problem getting it to work, just ask for more help with it:

One way to deal with disabling sets of buttons is to have a function that enables/disables them all, as in...

function enableBtns(truefalse){
for(i=1; i<6; i++){
this["mycase"+i+"_btn"].enabled = truefalse;
}
}

Then, within the button functions, you call the function to disable them all along with whatever you do to get the movelip playing...

on(release){.... // depends how you code your buttons

// start the movieclip....

// disable the buttons
enableBtns(false);

}

And when the movieclip finishes playing you need to have the buttons enabled again... which you can have in the last frame of the movieclip.

_parent.enableBtns(true);
May 13, 2008
I did see your earlier reply but couldn't get it working. I will look at your latest reply and maybe I can get it working. I appreciate the help.