Variables

A variable is a named location in memory where you can store values. Before you can use a variable, you must declare it using a good name and a type. You can also give it an initial value. For thes examples, we will use int (integer values)

Declaration:

A variable dx is declared as shown below. Notice that a variable can be given an optional initial value when it is declared.

  var dx: int=0;
  var dy: int=0;

Scope

Assignment Statements

A variable can be assigned a value with the assignment statement.
The format is: variable = newvalue;
Examples:
      The new value can be a constant: dx = 5;
      The new value can be another variable: dx = dy;
      The new value can be a property: dx = ball.y;
      The new value can be an expression: x = y/3;
      It can even use its current value in the expression: x = x + 1;
      The last statement is called incrementing and can also be written: x++;
      The last two statements assign a new value to x that is one more than its current value.

INDEX, Variables, Blast Off!, Relaunch and fire, Select a star to spin, Select ANY star to spin
Next lesson: Arithmetic Operations in Actionscript

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Variables