# \[MX04\] Working out end of motion

**URL:** <https://forum.kirupa.com/t/mx04-working-out-end-of-motion/249799>\
**Category:** flash\
**Created:** [January 22, 2008, 5:11pm UTC](https://forum.kirupa.com/t/mx04-working-out-end-of-motion/249799 "2008-01-22T17:11:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tempyyyst](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@tempyyyst](https://forum.kirupa.com/u/tempyyyst)\
**Post date:** [January 22, 2008, 5:11pm UTC](https://forum.kirupa.com/t/mx04-working-out-end-of-motion/249799/1 "2008-01-22T17:11:01Z")

</div>

Hi all

I’ve been playing with the Kirupa gravity tutorial here:

[http://www.kirupa.com/developer/actionscript/gravity.htm](http://www.kirupa.com/developer/actionscript/gravity.htm)

At the end of the motion I want to jump to a new movieclip and remove this one

I thought of placing this in the onClipEvent(EnterFrame)

```auto
   
 if (this._y == floor && speedy == 0) {
    _root.particles.gotoAndPlay(2);
 }

```

But no joy.

Does anyone have any suggestions for detecting the end of the bounce and jumping to the new movieclip?

Just in case I’ve messed up the original code too much, here’s what I have minus the test for motion stopping:

```auto

onClipEvent (load) {
    stop();
    gravity = 5 ;

    // We get the time when the ball is released for the
    // first time. Be careful with the division by 100
    time = getTimer () ;
    time /= 100 ;
    
    floor = 300 ;
    
    bounce = 0.5 ;
    
    // We set the speed of the ball when it is released.
    speedx = 0 ;
    speedystart = 0 ;
}

onClipEvent (enterFrame) {

    // We get the current time (still /100)
    timenow = getTimer () ;
    timenow /= 100 ;
    speedy = gravity * (timenow - time) + speedystart ;
    
    //We move the ball
    //this._x += speedx/5 ;
    this._y += speedy/5 ;
    
    if (this._y > floor) {
        this._y = floor ;
        speedy *= -bounce ;
        time = getTimer () ;
        time /= 100 ;
        // reset the timer
        speedystart = speedy ;
        // reset the starting speed
    }
}

```

Thanks in advance…
