Game Development Reference
In-Depth Information
Variables and properties
The above example shows a few more things about the ActionScript 3 language
elements, such as defining a variable You first need to tell the compiler that you
are defining a variable via the var keyword, followed by a name of your choice,
followed by a colon ( : ), and then the type of the variable.
Here are some examples:
var anInteger:int = 3;
var anArray:Array = new Array();
var yesOrNo:Boolean = false;
A class is also referred to as a user-defined type, meaning that by creating a new
class you are also creating a new data type that can be assigned to a variable just like
the ones you may have used such as int, float, and so on. However, we still make a
distinction between a primitive datatype such as an int and/or a complex datatype
such as a class. Primitive datatypes such as an int and float do not offer any methods
like a class, but only a placeholder to store the value of the type.
But Actionscript 3 is very different from the other programming languages you may
have come across. In AS3, everything is a class! To store and manipulate numbers,
AS3 provides int and Number classes. To store strings, it offers the String class.
More specifically, an int class lets us manipulate signed 32-bit integers and uint
lets us manipulate unsigned 32-bit integers. The Number class lets us manipulate a
floating point number.
Let's see the variables in action, assign values to the variables, and have them print it.
Here is the listing:
package {
import flash.display.Sprite;
import world.Avatar;
public class HelloWorld extends Sprite
{
public function HelloWorld()
{
// This is a comment.
/* This is a comment as well and is multi-line
we can declare the variable and assign an initial
value!*/
var anInteger:int = 3;
var aNumber:Number = 3.1415;
var aString:String = "This is a string."
 
Search WWH ::




Custom Search