|
-
Disabling button once click - code not working
I have six frames and six buttons that should navigate from frame to frame (each frame contains a different movie clip). I am trying to make it so that when I click on a button and it goes to the frame specified, that button becomes disabled while on that frame. Then if I click on a different button, THAT one becomes disabled after I go to the frame and the previous button becomes enabled again. The code below is not working ... it disables the button when I click another (move to a diff frame), but it doesn't enable it again, so basically ALL the buttons become inactive/disabled permanently.
What's wrong? Here's the code I have:
stop();
happy_btn.addEventListener(MouseEvent.CLICK, onHappyClick);
sad_btn.addEventListener(MouseEvent.CLICK, onSadClick);
angry_btn.addEventListener(MouseEvent.CLICK, onAngryClick);
tired_btn.addEventListener(MouseEvent.CLICK, onTiredClick);
scared_btn.addEventListener(MouseEvent.CLICK, onScaredClick);
surprised_btn.addEventListener(MouseEvent.CLICK, onSurprisedClick);
function onHappyClick(evt:MouseEvent):void {
gotoAndPlay("happy")
happy_btn.mouseEnabled = false;
}
happy_btn.mouseEnabled = true;
function onSadClick(evt:MouseEvent):void {
gotoAndPlay("sad")
sad_btn.mouseEnabled = false;
}
sad_btn.mouseEnabled = true;
function onAngryClick(evt:MouseEvent):void {
gotoAndPlay("angry")
angry_btn.mouseEnabled = false;
}
angry_btn.mouseEnabled = true;
function onTiredClick(evt:MouseEvent):void {
gotoAndPlay("tired")
tired_btn.mouseEnabled = false;
}
tired_btn.mouseEnabled = true;
function onScaredClick(evt:MouseEvent):void {
gotoAndPlay("scared")
scared_btn.mouseEnabled = false;
}
scared_btn.mouseEnabled = true;
function onSurprisedClick(evt:MouseEvent):void {
gotoAndPlay("surprised")
surprised_btn.mouseEnabled = false;
}
surprised_btn.mouseEnabled = true;
-
Your code simply keeps on disabling the buttons. Why not enable other buttons when the selected one is disabled? Something like this:
Code:
function EnableAllButtons():void{
happy_btn.mouseEnabled = true;
sad_btn.mouseEnabled = true;
angry_btn.mouseEnabled = true;
tired_btn.mouseEnabled = true;
scared_btn.mouseEnabled = true;
surprised_btn.mouseEnabled = true;
}
just define this function and then add it to the beginning of your even listener functions:
For instance,
Code:
function onHappyClick(evt:MouseEvent):void {
EnableAllButtons();
gotoAndPlay("happy")
happy_btn.mouseEnabled = false;
}
Hope this helps.
-
Yea, that works! Thanks a million.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|