March 27, 2009

Jumping Football

প্রথমে কিছু জিনিস তৈরী করতে হবে।

প্রথমে আপনাকে একটা বল তৈরী করতে হবে, অথবা একটা বলের ছবি বাহির করতে হবে। এবং সেই সাথে আপনাকে সেটাকে মুভিক্লিপ হিসেবে কনভার্ট করতে হবে। এবং instance name দিন ball_mc

actionscript 3.0 ball bouncing in 3d space

এবার কিছু একশনস্ক্রিপ্টিং করতে হবে।

// 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);

}

No comments:

Post a Comment