Flash AS3 Button Up-Down Effect

Posted on 2012-09-14
Last Modified: 2012-09-19
How can I get my buttons to move down with MOUSE_DOWN, and back up whether the MOUSE_OUT or MOUSE_UP event occurs?
If I have MOUSE_OUT move the button -2 x,y it does it whenever I roll over the button...

I'm using movieClips instead of buttons... I'd rather keep it that way, if possible (instead of convert each to a button to use built-in features).

home_i.addEventListener(MouseEvent.MOUSE_DOWN, fx_down);
function fx_down(event:MouseEvent):void
{ = + 2; = + 2;

home_i.addEventListener(MouseEvent.MOUSE_UP, fx_pause);
function fx_pause(event:MouseEvent):void
{ = - 2; = - 2;
Question by:tlengnick
    LVL 39

    Accepted Solution

    i'm not sure what you're trying to do.
    if you want it to move down on mouse over and mouse down, and revert back to original position when mouse down or mouse out, simply add 4 listeners.

    Author Comment

    Sorry. I realize I didn't explain the problem!

    Based on the way I have it coded above, the user could hold the mouse down over the button, triggering the MOUSE_DOWN function (and moving the button +2x +2y), but if while continuing to hold the mouse down the user moves it away from the button and then releases, the MOUSE_UP function (moving the button -2x -2y, i.e., back in place) never occurs.

    The button would stay "depressed", and the user could move it another +2x +2y by clicking on it again, eventually moving it off the stage.
    LVL 12

    Assisted Solution

    Try this instead:

    stage.addEventListener(MouseEvent.MOUSE_UP, fx_pause);

    Open in new window


    Author Closing Comment

    Thank you both for the suggestions -- I actually used each for different solutions!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now