Example
Basic.as
Package
Package
{
Import Package
Import Flash.display.Sprite;
Basic class inherits from Sprite
Only one class can be defined within a package
Class name must be the same as file name
public class Basic extends Sprite
{
Constructors
Public Function Basic ()
{
Trace ("Hello ActionScript");
Output:hello ActionScript
Data type (everything is Object)
Showdatatype ();
Default values for individual objects
Showdefaultvalue ();
Operator
Showoperator ();
Process Control Statements
Showflowcontrol ();
}
Data type (everything is Object)
function Showdatatype (): void
{
Declaring constants
CONST C:STRING = "Const WEBABCD";
Trace (c);
Output:const WEBABCD
Integral type
var i:int =-100;
Trace (i);
Output:-100
Boolean value
var B:boolean = true;
Trace (b);
Output:true
Number type (time with decimal)
var n:number = 100.123;
Trace (n);
Output:100.123
Positive integer
var u:uint = 100;
Trace (U);
output:100
String
var s:string = "WEBABCD";
Trace (s);
Output:webabcd
One-dimensional Array (Assignment initial value)
var a:array = new Array (1,2,3);
Trace (a[0]);
Output:1
One-dimensional Array (Assignment initial value)
var a2:array = [1,2,3];
Trace (a2[1]);
Output:2
One-dimensional array (specify array length)
var a3:array = new Array (3);
A3[0] = 1;
A3[1] = 2;
A3[2] = 3;
Trace (A3[2]); 3
Output
Two-dimensional Array (Assignment initial value)
var aa:array = [[1,2,3], [4,5,6], [7,8,9]];
Trace (aa[0][0]);
Output:1
Two-dimensional array (specify array length)
var aa2:array = new Array (3);
Aa2[0] = [1,2,3];
AA2[1] = [4,5,6];
AA2[2] = [7,8,9];
Trace (aa2[0][0]);
Output:1
Date type
var d:date = new Date ();
Trace (d.todatestring ());
Output:mon Nov 12 2007
Declaring a new object
var o:object = new Object ();
var o:object = {};
Declares a new object and writes the property at the same time
var o:object = {nickname: "Webabcd", Age: "27"};
Add properties dynamically to an object
o["Salary"] = 1000;
Trace (O.nickname);
Output:webabcd
Trace (o.age);
Output:27
Trace (o.salary);
output:1000
Delete can only delete dynamically added properties
Delete o.salary;
Trace (o.salary);
output:undefined
}
Default values for individual objects
function Showdefaultvalue (): void
{
var i:int;
Trace (i);
output:0
var u:uint;
Trace (U);
output:0
var N:number;
Trace (n);
Output:nan
var s:string;
Trace (s);
Output:null
var B:boolean;
Trace (b);
Output:false
var A:array;
Trace (a);
Output:null
var o:object;
Trace (o);
Output:null
var d:date;
Trace (d);
Output:null
var xxx;
Trace (XXX);
output:undefined
var yyy:*;
Trace (YYY);
output:undefined
}
Operator
function Showoperator (): void
{
/**//* the following operations Fu Tong C #
+ - * / %
+= -= *= /= %=
== !=
= = =!=== (operator on both sides do not do type conversion)
>= <= > <
&& | | !
? :
*/
Returns the type of the object as a string
Trace (typeof "Webabcd");
Output:string
Determines whether an object belongs to a type
Trace ("Webabcd" is String);
Output:true
If the object belongs to a type, the object is returned
Trace ("Webabcd" as String);
Output:webabcd
Returns NULL if the object does not belong to a type
Trace ("WEBABCD" as number);
Output:null
var ary:array = [1,2,3];
Determines whether an object belongs to a set
Trace (1 in ary);
Output:true
}
Process Control Statements
function Showflowcontrol (): void
{
/**//* the following process control with C #
If-else If-else
While loop
Do-while Cycle
For loop
Switch-case
Break continue
*/
var ary:array = [1,2,3];
The enumeration variable for each-in represents a member of the collection
For each (Var v. in ARY)
{
Trace (v)
}
Output
1
2
3
For-in enumeration variables represent the collection index
For (var k in ary)
{
Trace (Ary[k])
}
Output
1
2
3
}
}
}
Ok
Source: http://www.cnblogs.com/webabcd/archive/2007/11/13/957471.html