Tuesday, December 21, 2010

Summary of Actionscript 3.0


ActionScript 3.0 is a case-sensitive language
 1. variable
Use var to create a variable:
var myVar;
var myVar:String;
var myVar:String = "Hello World!";

2. Data type:
Boolean, int, Null, Number(used for integers, unsigned integers, and floating-point numbers), String, unit, void, Object (the base class for all class definitions in ActionScript).

3. Code comments:
//This is a comment
/*
This is a comment
/
4. Trace()
Traced values are rendered to the output window when we export for debugging(Pressing Ctrl+Enter).
Example:
var myNum:uint = 10;
trace(myNum); // output is 10

5. The Semicolon
The semicolon( ; ) is used to terminate a statement

6. Creating a Sound object and a Datagrid object.
var mySound:Sound = new Sound();

var myGrid:DataGrid = new DataGrid();

7. Using if..... else if..... and else

var numA:uint = 5;
var numB:uint = 5;

if (numA != numB) {
trace("Numbers do not match");
} else {
trace("Numbers match");
}

8. for loop

var i:uint;
for (i = 1; i <= 4; i++)
{ trace(i); }



var myArray:Array = ["France", "Great Britain", "Italy", "Germany"];

for (var place:String in myArray) {

trace(myArray[place]);

}



9. for each ( in ) loop
var myArray:Array = ["France", "Great Britain", "Italy", "Germany"];

for each (var place:Object in myArray) {

trace(place);

}
10. Built-in core function, such as Math.round() in this example
var myNum:Number = 5.7;

var roundedNum:uint = Math.round(myNum);

trace(roundedNum);

11. Custom Function
function sayHelloWorld () {
var string1:String = "Hello ";
var string2:String = "World!";
var myPhrase:String = string1 + string2;
trace(myPhrase);
}

sayHelloWorld();
 --------------------------------------------------------
function with arguments:
var string1:String = "Hello World!";

function sayHelloWorld (var1:String) {
    
    trace(var1);
}

sayHelloWorld(string1); 


12  Using the rest(...)  operator to send array data into functions

function myFunction(... argArray):void {

for (var i:uint = 0; i < argArray.length; i++) {
trace(argArray[i]);
}

}
myFunction("Joe", "Betty", "Suzy", "William");

13. Returning Values From Custom Created Functions

var v1:String = "Hello ";
var v2:String = "World!";

function sayHello (var1:String, var2:String):String {

var myPhrase:String = var1 + var2;
return(myPhrase);

}

var storedResult:String = sayHello(v1, v2);

trace(storedResult); // output the stored result to view it

No comments:

Post a Comment