New Variable Types
ActionScript 3 supports a wide range of variable types including some which were not present in previous versions of ActionScript. Basic types for AS3 include:
Primitive:
- Boolean
- int
- null
- Number
- String
- uint
- undefined
Complex:
- Object
- Array
- Date
- Error
- Function
- RegExp
- XML
- XMLList
Additional types also exist that relate to their classes; ex: Matrix (flash.geom.Matrix), Shape (flash.display.Shape), URLRequest (flash.net.URLRequest), etc.
Things to note:
- The special Void type has changed in AS3 to be lowercase (void not Void)
- There's a new * type that is used to represent any data type. This should be used instead of ommitting typing information for your variables.
ActionScript Code:
var anything:*;
- The XML type is not the same as the XML type in ActionScript 1 and 2. The old XML type (object) is now defined as XMLObject. XML now references the new E4X-based XML object.
- int and uint are new primitive number data types for integer (numbers without decimal values) and unsigned integer (numbers without decimal values that also cannot be negative). These can be useful for values which are not supposed to have decimal values such as loop iterators. The int data type will provide a small perfomance boost when used over Number in most cases, but uint should only be used when necessary such as with color values.
0 评论:
发表评论