A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: How to disable a button/action after a single click?

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    4

    How to disable a button/action after a single click?

    So what im trying to do is have a few buttons that when pressed go to and play a movie symbol at keyframes throughout the timeline.

    Say there was a picture of a man, and you click button A and the picture zooms in on the mans head, button B zooms in on his hand and button C zooms in on his foot.
    I have all the motion tweening setup and all the buttons work via AS3 using gotoandplay, and there is a stop at each step of the way.

    Thats all fine, it works perfectly, however the only issue I have is, say you click button A it plays the part that zooms in on his head, but if you click A again buring the tween/playback it goes back and starts playing again.
    Basically what im after, is once you click a button, it becomes no longer clickable untill it gets to next step.
    I can disable the button symbol itself using the buttonA.enabled=false; but as the script is on a seperate layer, that doesnt do anything at all. It just stops the button from being a button.. the area ist sitll clickable due to the script. And you cant put scripts within the buttons themselves.

    The script im using is
    menubutton1.addEventListener(
    MouseEvent.MOUSE_UP,
    function(evt:MouseEvent):void {
    gotoAndPlay(2);
    }
    );


    So is there anyway of disabling the gotoand play function between the keyframes. So that if the button is clicked during the tween/playback it doesnt do anything?
    I have tried putting a script on the next frame, that doesnt have the gotoandplay portion but that didnt do anything.

    (sorry thats a right mess, hope it all makes sense.)

    <edit>
    I have tried what is mentioned here..http://board.flashkit.com/board/showthread.php?t=766152
    But it doesnt seem to be working, perhaps im not putting in the script right or putting it in the wrong spot. As the buttin is still perfectly clickable.

    I have keyframe every 15 frames, which has action script in it. to control what the buttons do on that frame.
    Last edited by DaForce2000; 05-04-2008 at 10:19 AM.

  2. #2
    I would remove the event listener from menubutton1. I would also not create the function inside the parameter.


    Code:
    menubutton1.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);                                           
    
    function mouseUpHandler(evt:MouseEvent):void {
       gotoAndPlay(2);
       menubutton1.removeEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
    }
    What I did is added that removeEventListener function to the mouseUp Handler function. This stops menubutton1 from listening to Mouse Up Events which call mouseUpHandler.

    Now when that tweening is complete call the same exact addEventListener from that 1st line.

    You might have to find menubutton1 from the position of where your tweening occurs. I don't know where your clips are located and such, so i can't really help you there.

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    4
    wow thanks works perfect. Thanks!!

    Only problem is (and im not sure if there will be a work around)
    Is on the first keyframe, there is 3 buttons, so basically pasted 3 times, and the button names changed accordingly.
    I notice i also need to increment "mouseuphandler" as well to mouseuphanlder1..2..3 ..etc so given there will be about 20-30 entries i just increment as necessary.. or is there a way around this?
    As when you click a button it plays 15frames or so and stops, then those buttons need to be clickable, so the same script is used except now i need mouseuphandler 4,5,6
    Is that just the way it needs to be?

    Cheers

    excuse any stupid questions, pretty much a newb at AS3.. and most sorts of script/code TBH

  4. #4
    you can reuse the same function.

    Code:
    function mouseUpHandler(evt:MouseEvent):void {
       gotoAndPlay(2);
       evt.currentTarget.removeEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
    }
    the currentTarget is what is calling the event, and that is the movieclip you called the addEventListener for.

  5. #5
    Senior Member
    Join Date
    Jun 2007
    Posts
    204
    target_button.mouseEnabled = false;

    Removes the listener and the hand cursor doesn't appear when rolled over.

  6. #6
    Junior Member
    Join Date
    May 2008
    Posts
    4
    @tariqm
    It seems using that still gives dupilicate definition.

    @moose-o
    Well that seems to work pretty well with my original code.
    Thanks

  7. #7
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    PHP Code:
    yourMovieClip.addEventListener(MouseEvent.MOUSE_UPmouseUpHandler);

    function 
    mouseUpHandler(event:MouseEvent):void 
    {
       
    gotoAndPlay(2);
       
    event.target.removeEventListener(MouseEvent.MOUSE_UPmouseUpHandler);

    Use target instead of currentTraget, it should work.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  8. #8
    Junior Member
    Join Date
    May 2008
    Posts
    4
    Sweet, will give that a shot thanks.

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