A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Checking if animation has already happened in AS3.

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    24

    Checking if animation has already happened in AS3.

    In my project, I have an animation play on rollover, but I only want it to be able to happen once... So I want to disable the rollover code if it's already happened once (and have the mc that animated stay in it's finished state).

    This is the code I currently have...

    Code:
    button_mc.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
     
    function manageMouseOver(event:MouseEvent):void{
      gotoAndPlay("2");
    }

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    I dont think you want to handle stoping the movieclip from your button. It would be best to tell your animation to stop within its own timeline.

    If your animation is in its own MovieClip, you just need to add a stop(); action on the last frame of your animation.

  3. #3
    Junior Member
    Join Date
    Nov 2008
    Posts
    24
    Right... Currently there is a stop on frame 1, and on the last frame.

    So on rollover it goes to frame 2 and plays to the end... but currently if you rollover again, it goes back to frame 2 and replays the animation.

    I want it to be locked onto that last frame if it's already been rolled over.

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    There are two ways to handle this:
    1) You could just remove the event listener for the RollOver.
    function manageMouseOver(event:MouseEvent):void{
    gotoAndPlay("2");
    button_mc.removeEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
    }

    2) You can create a variable and have a conditional statement
    var isRolledOver:Boolean = false;

    function manageMouseOver(event:MouseEvent):void{
    if(isRolledOver==false){
    gotoAndPlay("2");
    }
    isRolledOver = true;
    }

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