A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: how to make a button to be clickable only ONCE.

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1

    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);

    }

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Posts
    7
    There are a few ways you could go about fixing this. This thread may help:
    http://board.flashkit.com/board/show...a-single-click

  3. #3
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    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.

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center