A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: pause animation on mouse over

  1. #1
    Member
    Join Date
    Mar 2005
    Location
    Study Bristol UK. Live Southampton UK
    Posts
    43

    pause animation on mouse over

    I would like a button on a keyframe mid-animation to stop the timeline if the mouse is over it and when the mouse rolls out of the button it continues to play.
    I am a actionscript newbie and I am having some hard time trying to achieve this.

    Is there a method like this that will work?:

    if(MOUSE_OVER.btn_hold){
    then stop();
    } else if(MOUSE_OUT.btn_hold){
    play();
    } else {
    play();
    }

  2. #2
    Member
    Join Date
    Mar 2005
    Location
    Study Bristol UK. Live Southampton UK
    Posts
    43
    Would I have to put on enterframe event?

    Any help will be kindly appreciated..

  3. #3
    Member
    Join Date
    Mar 2005
    Location
    Study Bristol UK. Live Southampton UK
    Posts
    43

    ....maybe

    I was hoping this is would work but it doesn't:

    onClipEvent(enterFrame){

    if(_root.btn_pause.hitTest(_root._xmouse,_root._ym ouse, true)){

    _root.stop();

    }else{

    _root.play();

    }

    }


    I was hoping there was a simple answer but I guess it's harder than i first thought.

  4. #4
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi,

    Insert this code inside the first frame in the main timeline:
    [this assumes that the "btn_hold" is located directly in the main timeline (mean not inside another movie clip)]
    This will pause the aniamation in the main (_root) timeline

    Code:
    btn_hold.onRollOver=function(){
    	stop()  // Or use: _root.stop();
    }
    btn_hold.onRollOut=function(){
    	play()  // Or use: _root.play();
    }
    K. Zotos online portfolio: http://www.in3d.eu

  5. #5
    Member
    Join Date
    Mar 2005
    Location
    Study Bristol UK. Live Southampton UK
    Posts
    43
    Hi Kostas Zotos,

    Thank you for your reply.

    Since my last post I have changed what I need to do to when the mouse is down and up instead of rollover rollout.

    So I tried this:


    stop();

    btn_hold.onMouseDown=function(){
    _root.stop()
    }
    btn_hold.onMouseUp=function(){
    _root.play()
    }


    The thing is it doesn't work. Maybe I am doping something wrong?


    What I would like to have is an animation 60 frames long. The first frame is stopped. When a button is pressed it starts. Half way through the animation the start button is replaced with an identical one (btn_hold). This button checks to see if the mouse is still down on it. If it is the timeline stops until the mouse is up, otherwise it continues to frame 60 without stopping.

    Can you help me do this?

  6. #6
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Your welcome!

    Here is an example code (to be inserted in a script layer in the main -root- timeline). The following code uses only one button for start and check the animation.

    It requies a buton (not movie clip) named "myButton", located directly in the main timeline. When the button pressed, starts the main's time line animation (any children clip's animation play independent of the main timeline of course)

    In every frame, check if the button is still pressed [if the "isPressed" variable is true, and the playhead -of main timeline- is halftime (totalframes/2) then the animation stop].

    If the button is not pressed ("isPressed=false") (when timeline is halfway) then the animation (of main timeline) continue to play..

    PHP Code:
    var isPressed false;  // A custom variable to track the press state

    myButton.onPress = function() {
        
    play()    
        
    isPressed=true
    }

    myButton.onRelease = function() {
        
    play()
        
    isPressed=false
    }

    // In case the user releases the mouse  outside of button's area
    myButton.onReleaseOutside=myButton.onRelease

    this
    .onEnterFrame = function() {
        
    trace(_currentframe// Just for test.  (You may deldete this line)
        
    if ((_currentframe == _totalframes/2) && isPressedstop();
    }

    stop() 
    Kostas
    K. Zotos online portfolio: http://www.in3d.eu

  7. #7
    Member
    Join Date
    Mar 2005
    Location
    Study Bristol UK. Live Southampton UK
    Posts
    43
    Kostas!

    You are a hero!

    I can't thank you enough for the help you have given me. Your script works perfectly. It is just what I have been trying to achieve!

    I will study the script you've given me and learn exactly how it works as it's a great advance in the project I am doing.

    Thanks again. you've made me really happy!

  8. #8
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Ohh.. No, Just like the ordinary people

    Your welcome!

    Bye!
    K. Zotos online portfolio: http://www.in3d.eu

  9. #9
    Junior Member
    Join Date
    May 2009
    Posts
    1

    Talking small cuestion

    could you explain that in a simple way cause im a begeiner and i have no clue of how to make my flash movie pause on mouseover.

    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