-
how to make a button to be clickable only ONCE.
I Have three answer choices for a question. (codes below)
if 1 button has been clicked, the other 2 buttons will be disabled.
But .. apparently, the same button can be clicked more than once. How do i do to stop that ? and only allow 1 click.
//CHOICE A
function ona1Click(evt:MouseEvent):void {
Q1a = new Loader();
bb1.removeEventListener(MouseEvent.CLICK, onb1Click);
cc1.removeEventListener(MouseEvent.CLICK, onc1Click);
var myQ1a:URLRequest=new URLRequest("wrong.png");
Q1a.load(myQ1a);
addChild(Q1a);
Q1a.x=320;
Q1a.y=180;
}
//CHOICE B
function onb1Click(evt:MouseEvent):void {
Q1b = new Loader();
aa1.removeEventListener(MouseEvent.CLICK, ona1Click);
cc1.removeEventListener(MouseEvent.CLICK, onc1Click);
var myQ1b:URLRequest=new URLRequest("tick.png");
correctAnswers++;
Q1b.load(myQ1b);
addChild(Q1b);
Q1b.x=320;
Q1b.y=260;
}
//CHOICE C
function onc1Click(evt:MouseEvent):void {
Q1c = new Loader();
aa1.removeEventListener(MouseEvent.CLICK, ona1Click);
bb1.removeEventListener(MouseEvent.CLICK, onb1Click);
var myQ1c:URLRequest=new URLRequest("wrong.png");
Q1c.load(myQ1c);
addChild(Q1c);
Q1c.x=320;
Q1c.y=340;
}
//NEXT --> AND REMOVE IMAGE
function onNext1Click(evt:MouseEvent):void {
if(Q1a)
removeChild(Q1a);
if (Q1b)
removeChild(Q1b);
if(Q1c)
removeChild(Q1c);
gotoAndPlay(4);
}
-
There are a few ways you could go about fixing this. This thread may help:
http://board.flashkit.com/board/show...a-single-click
-
Senior Member
Why not just removeListener() to the button clicked? An alternative is button.mouseEnabled = false - if you re-use the same buttons then just, change to true on reset.
-
I would create a function to Disable all buttons then call that function from your clicked function.
function disableButtons():void{
aa1.removeEventListener(MouseEvent.CLICK, ona1Click);
bb1.removeEventListener(MouseEvent.CLICK, onb1Click);
cc1.removeEventListener(MouseEvent.CLICK, onc1Click);
//or as steven FN said, you can use the .mouseEnabled method
}
funtion onb1Click(e:MouseEvent):void{
//all of your other code
disableButtons();
}
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
|