Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
Creating A 2D Bouncing Ball I Tween Class  


Download

Actionscript

import mx.transitions.Tween;
import mx.transitions.easing.*;

new Tween(ball_mc, "_y", Bounce.easeOut, ball_mc._y, 250, 3, true);
new Tween(ball_mc, "_x", None.easeNone, ball_mc._x, 400, 3, true);






Note:
Press the "refresh" button in the browser to play the animation again.


// The tween transition class is imported.


import mx.transitions.Tween;

// This uses the "wilcard" symbol "*" to import all six of the easing classes in a package.
// This package contains multiple classes in a single directory folder.


import mx.transitions.easing.*;

// A new tween is constructed and defined using the tween class syntax:
// Tween (object, property, function, begin, end, duration, useSeconds).

new Tween(ball_mc, "_y", Bounce.easeOut, ball_mc._y, 250, 3, true);

// The object being tweened is ball_mc.
// The property "_y" indeicates the vertical position of the movie clip is to be tweened.
// Bounce indicates that the ball will bounce moving up and down and reducing its height after each bounce.
// easeout dictates to the movie clip that its motion decelerates toward the end of the transition.
// ball_mc_y sets the initial position of the movie clip Ball_mc as the stating point for the transition.
// 250 sets the final coordinates of the movie clip.
// 3 sets the duration of the animation to 3 units.
// true uses boolean logic to set the units for the duration fo the tween to seconds.

// This transition acts only on the horizontal position of the movie clip.

new Tween(ball_mc, "_x", None.easeNone,ball_mc._x, 400, 3, true);

// None.easeNone Sets the movie clip to move at a constant rate during the transition with acceleration or deceleration.


© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us