# As3 version of Spoono's bounce tutorial

**URL:** <https://forum.kirupa.com/t/as3-version-of-spoonos-bounce-tutorial/299336>\
**Category:** flash\
**Created:** [November 3, 2009, 3:44pm UTC](https://forum.kirupa.com/t/as3-version-of-spoonos-bounce-tutorial/299336 "2009-11-03T15:44:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamyo](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jamyo](https://forum.kirupa.com/u/jamyo)\
**Post date:** [November 3, 2009, 3:44pm UTC](https://forum.kirupa.com/t/as3-version-of-spoonos-bounce-tutorial/299336/1 "2009-11-03T15:44:51Z")

</div>

Hi all.

So I decided to have a stab at turning the Gravity tutorial at [http://www.spoono.com/flash/tutorials/tutorial.php?url=gravity](http://www.spoono.com/flash/tutorials/tutorial.php?url=gravity), into Actionscript 3.

I just tried to do the basics but I ran into a problem when getting the ball to be thrown around. There are these \_x, \_y variables I havn’t used before so not sure how to convert them. They are not supported in AS3. My unfinished code attempt is as follows:

```auto

var xPos = 0;
var yPos = 0;

var xVel:Number = 0;  
var yVel:Number= -10;

var gravity:Number =1;
var restitution:Number = 0.7;
var friction:Number = 0.9

var dragging:Boolean = false;

// Mouse variables
var oldX:Number;
var oldY:Number;

this.addEventListener(Event.ENTER_FRAME, update);

ball_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
ball_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
    

function update(e:Event):void
{
    if(!dragging)
    {
        yVel += gravity;        
        
        ball_mc.x += xVel;
        ball_mc.y += yVel;
            
                
        if( ball_mc.y > 400 )
        {    
            ball_mc.y= 400;
            yVel *= -restitution;                   
            xVel *= friction;
        }
    }
    else {
        oldX = ball_mc.x;
        oldY = ball_mc.y;
                
        xVel = (mouseX - oldX) / 2;
        yVel = (mouseY - oldY) / 2;
    }
}

function drag(e:MouseEvent)
{
    startDrag();
    dragging = true;
}

function drop(e:MouseEvent)
{
    stopDrag();
    dragging = false;
}

```

The ball bounces fine to start with and then the first throw upwards seems to work but bounces on a plane higher up the stage. It then won’t work. It must be the mouse code. Anyone converted this to AS3? Many thanks
