Getting Started - Simple Math and Movieclip Properties PDF Print E-mail
Written by Smash   
Thursday, 16 July 2009 13:37

How do we use math in ActionScript 3.0?

Using math in ActionScript 3.0 is pretty painless.

I would suggest watching the video at the buttom of this page first for a better understanding of the text

You can add use mathimatical equations on 2 variables like this, placing them in a 3rd variable

numA = numB + numC; //Addition
numA = numB - numC; // Subtraction
numA = numB * numC; // Multiplication
numA = numB / numC; // Division

If you need to use multiplication/division along with addition/subtraction in the same equation, you need to use parenthasis to encapsulate what you need done first, like this

numA = (numB + numC) * numD;

If you didnt use parenthasis, then numC would get multiplied first, then numB would be added to the result.

As you saw in the video we can manipulate Movie Clips in ActionScript by changing their properties. If our Movieclips instance name is myMovieClip, we could manipulate myMovieClip in a number of ways like this

myMovieClip.x = 100;//Change this to change the X value or horizontal position
myMovieClip.y = 100;//Change this to change the Y value or verticle position
myMovieClip.height = 100; //Change this to change the MovieClips height
myMovieClip.width = 100; //This changed its width
myMovieClip.rotation = 100;//Change this to change the rotaion or which direction the movieclip is spun
myMovieClip.alpha = 0;//Change this from 0 - 1 and anything in between, alpha 1 being solid and alpha 0 being invisable

 

 
Home > Tutorials > ActionScript 3.0 > Getting Started - Simple Math and Movieclip Properties