Author: fbysss
MSN: jameslastchina@hotmail.com
Blog: blog.csdn.net/fbysss
Disclaimer: This article is original from fbysss. for reprinting, please indicate the source
Keywords: as3, actionscript
Introduction:
If you have a basic knowledge of Java and JavaScript, The as syntax is easy to understand and there is a good morning. After reading this article, you can write code for debugging.
1. Development Tools
Flashbuilder. When you create a new [ActionScript] project, an as file is automatically generated and you can directly write code in it for testing.
In terms of structure, this file is a class, similar to the Java syntax.
2. As syntax
VaR keyword definition, Trace Output
Variable definition:
VaR I: Int = 100;
Trace ("I =" + I );
Array
VaR myarray: array = (1, 2, 3 );
Trace ("myarray [0] is:" + myarray [0]);
Object:
VaR person: Object =-{Name: "fbysss", Title: "manager", Gender: "male "};
Trace ("person. Name:" + person. Name );
Add Method
VaR person: Object =-
{Name: "fbysss", Title: "manager", Gender: "male ",
Sayhello: function (): void {
Trace ("Hello, I am" + person. Name); // trace ("Hello, I am" + person ["name"])
}
Salary: function (){
Return000000 )(;
}
};
Person. sayhello ();
Trace (person. Salary ());
Dynamically add class attributes and Methods
VaR person: Object = {};
Person. Name = "fbysss ";
Person. Title = "manager ";
Person. sayhello = function: void {
Trace ("Hello, I am" + person. Name );
}
Various types of default values
If Initialization is not performed,
Int, unit: 0
Number: Nan
String, object: NULL
Boolean: false
No type definition, such as var I; or var I: *;: Undefined
In keyword
VaR sssarray: array = {1, 2, 3 };
Trace ("2 in sssarray:" + (2 in sssarray); // true
Trace ("2 in sssarray:" + ("2" in sssarray); // true
Function Type
Function expression:
VaR sayhello: function = function (): void {
Trace ("helloworld ");
}
Sayhello ();
Obviously, sayhello can be called only after the statement is defined.
Normal Function Definition, consistent with JavaScript
Access parameter information
Similar to JavaScript. Is an arguments object
Arguments. length parameter count
Arguments. callee caller
Object-oriented
This part is similar to Java.
Package is not a semicolon, but curly brackets.
Event Mechanism
Differences between events and methods:
Events are triggered only when certain conditions are met. Passive calls
Methods may be called at any time; actively called
The caller and the called of the event may not be a process with low coupling.
Method calls must be in a process with strong coupling.
3. debugging method
F11
There is no main method. You can debug it through the constructor.
4. Notes
Number ("hello") output is Nan
But number ("hello") = Nan is always false
If you want to determine, you should use the IF (number ("hello") format, similar to Javascript
The switch statement is similar to JavaScript and supports the string type. Note break.
Q: dynamic parameters... rest? What is the purpose? -- There is a question here, because as3 and JavaScript directly support an indefinite number of parameters. What is the purpose?
A: In the object-oriented as3 class, it can be understood as a static language. This method must be used to support dynamic parameters (similar to Java's dynamic parameter practices ).
This parameter is not required for dynamically defined function variables.
Example:
Public class test (){
Publicfunction dynamicparam (){
For (vari = 0; I <Params. length; I ++ ){
Trace (Params [I]);
}
}
Publicfunction test (){
Dynamicparam (1, 2, 3 );
}
}