RSS link icon

Bouncing soccer ball with actionscript 

 

Hi all, well im not really sure what you can use this effect to, I just played around with flash for a while, and found a very easy way to make it look like a ball is bouncing back in space as a ball would on a floor.

So using actionscript we will do some simple transition tweens to make this effect, remember its made with actionscript 3.0, and will not work with previous versions of flash.

Hover the mouse cursor over the soccer ball to see the bouncing effect.

So before we do any coding we just need to do some simple preparations.

So we need to make a ball, I did it quite easy, just found an image of a ball. Now you need to convert it into a movieclip and give it an instance name, I named mine ball_mc.

 

actionscript 3.0 ball bouncing in 3d space

Now we are ready to do some actionscripting, I will try to explain line by line what Im doing with the actionscript code, some might seem a bit confusing, but its actually quite simple, and contains few lines of code.

// We will need to import some transition class to handle the tween effects.
import fl.transitions.*;
import fl.transitions.easing.*;

// Now we add some event listeners, to listen if the mouse is hovering the ball, if it is, then we call the function doMouseOver
ball_mc.addEventListener(MouseEvent.MOUSE_OVER, doMouseOver);
ball_mc.addEventListener(MouseEvent.MOUSE_OUT, doMouseOut);

// This is the actual function to scale out the ball and make it look like it getting closer to you.
function doMouseOver(event:MouseEvent):void {
    // we define a tween to scale on the x and y axis, make it bounce.easeOut, which actually makes it act like a ball.
    // also the number 1 is the size its scaled to, and 2 is the number of seconds the tween will happen in.
    var xT:Tween = new Tween(ball_mc, "scaleX", Bounce.easeOut, ball_mc.scaleX, 1, 2, true);
    var yT:Tween = new Tween(ball_mc, "scaleY", Bounce.easeOut, ball_mc.scaleY, 1, 2, true);
}

// this function do exactly the same as the one above, just scales it down, to make it look like its going away from you.
// and this event accrues when the mouse is no over the ball.
function doMouseOut(event:MouseEvent):void {
    var xT:Tween = new Tween(ball_mc, "scaleX", Bounce.easeOut, ball_mc.scaleX, .5, 2, true);
    var yT:Tween = new Tween(ball_mc, "scaleY", Bounce.easeOut, ball_mc.scaleY, .5, 2, true);
}

mion says: Tuesday, September 23, 2008

thank you very much your tut really helped me out


pankaj sharma says: Wednesday, July 23, 2008

this is nice actionscript coding i like it
and thanks


AB1 says: Tuesday, July 15, 2008

Nice tut! great effect! Thanks.


ganesh says: Wednesday, July 09, 2008

hey PLz send me this .swf file to this ID
ganesh.devre@routesms.com


Nilberto Junior says: Friday, July 04, 2008

Olá, muito bom o tutorial =]
já assinei até o RSS feed =}}

faloww

   


 

 

 

 3

 
 
   Web Premium
 
 

All rights reserved, Copyright 2008. Contact