Due to work needs, it is possible to take over the previous flashProgramStaff and colleaguesCodeToday, I read Action Script 3.0 and found that this is something really interesting...
Open Flash CS 4, create a new action script3.0 file, and write several lines of code in the first frame:
Code 1:
VaR o = "123"; trace (typeof (O) // output stringo = 123; trace (typeof (O) // output number
It seems pretty good. It's a bit of VaR in C #3.0. The variable type can be automatically inferred based on the value assignment.
Write a few more lines that are enjoyable:
Code 2:
VaR citys: array = ["Shanghai", "Beijing", "Wuhan", "Guangzhou", "Shenzhen"] For (var I in citys) {trace ("I =" + I + ", type:" + typeof (I) + ", element:" + citys [I])}
Output:
I = 0, type: Number, element: Shanghai
I = 1, type: Number, element: Beijing
I = 2, type: Number, element: Wuhan
I = 3, type: Number, element: Guangzhou
I = 4, type: Number, element: Shenzhen
It seems like the same thing, similar to that in C #, I is used as the numerical subscript of the array for element access (for example: citys [1]).
(Specifically, the type of the cyclic variable is defined as string ):
Code 3:
For (var j: String in citys ){
Trace ("J =" + J + ", type:" + typeof (j) + ", element:" + citys [J])
}
Output:
J = 0, type: String, element: Shanghai
J = 1, type: String, element: Beijing
J = 2, type: String, element: Wuhan
J = 3, type: String, element: Guangzhou
J = 4, type: String, element: Shenzhen
This seems to be quite awkward. If you explain it as an index reload (that is, citys ["1"]), then the J output value seems to be "1" more reasonable, the output result is 1 (without quotation marks, misleading beginners)
According to the test result in section 2, the loop variable is number by default, so let's try it like this:
For (var k: Number in citys ){
Trace ("type:" + typeof (k) + ", element:" + citys [k])
}
The irony is that it cannot be compiled! (In Code 2, the system automatically deduced the number type. Now I define it as number type but cannot compile it)
Maybe I am too simple to understand Adobe's xuanjicang.