Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
Simple Horizontal Linear Motion  

Download

Actionscript

var dt:Number = 0.2;
var v:Number = 20;

ball_mc._x = 10;

ball_mc.onEnterFrame = function(){
ball_mc._x += v*dt
};



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


First the variable "t" is declared, defined as a number and then assigned a value of zeo. The the variables dt and a.

var dt:Number = 0.2;
var v: Number = 20;


The movie clip "ball_mc" is set to a horizontal position of 10.

ball_mc._x = 10;

A function is created the is called everytime the movie clip "ball_mc" enteres a new frame.

ball_mc.onEnterFrame = function(){

Inside this a new function is created to calcualtes the acceleration which is exponentialy related to the time passed. This is then multipled by the acceleration factor "a", time passed "t" and the time interval "dt" to give the change in position.This value is then returned.

return ball_mc._x +=v*dt
}

Each time the mc enters a new frame an amount is added to the position of the mc. This amount exponentially increases as time increases causing the movie clip to exponentially accelerate off stage.


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