Actspt

how do you make something jump up then come down again using actionscript?heeeeeeeeeeeeellllllllllllllllllllppppppppppp!!!
:*(

Do you want it to just go up and back down, or do you want it to imitate gravity acting upon the ball so that when it hopes, gravity makes it fall again?

to just make it go up and back down again we could do a couple things

In this particular one, we’re assuming that you just want it to go up then down, then up then down, etc

Whatever object you want to hop up and down must be a movie clip.

With the action panel open, select this object and paste the following code.

//here we set a var to equal the present _y possition and a flag
//to trip whenever our object reaches max distance of travel
onClipEvent(load){
startLoc=_y;
flag=down;
}
//This is the part that does the work
onClipEvent(enterFrame){
//this first if, detects if the object is at the low point
if(flag==down){
//if it is, then it moves the object one pixel upwards.
_y–;
//now it detects to see if it has reached the top of the bounce
if(startLoc<startLoc-30){
//if it has, then it sets our flag to equal up
flag=up;
}
//this else says that if the flag is not “down” then do this instead
}else{
//move the object down one pixel
_y++;
//if the _y location is equal to startLoc again
if(_y==startLoc){
//set the flag equal to down.
flag=down;
}
}
}

You can change the -30 to any negative number you like if you want to increase the height which the object bounces.


doing gravity will require a little more explination. If you’re not satisfied with how the above looks, write back and I’ll try to explain velocity/gravity to you.