新的变量类型-ActionScript3 Tips and Tricks

本文是ActionScript3 Tips and Tricks系列阅读笔记之一New Variable Types,这里是原文地址

新的变量类型

ActionScript3支持更多的变量类型,基本的类型包括:

简单类型:

* Boolean
* int
* null
* Number
* String
* uint
* undefined

合成类型:

* Object
* Array
* Date
* Error
* Function
* RegExp
* XML
* XMLList

其他的类型涉及它们的类,例如:Matrix (flash.geom.Matrix), Shape (flash.display.Shape), URLRequest (flash.net.URLRequest)等等。

一些提示:

  • Void类型在AS3中改为小写(是void,不再是Void)
  • 用*来表示任意类型。例如:var anything:*;
  • XML类型与ActionScript1、2中的定义不同了,旧的XML类型现在定义为XMLObject。XML目前基于E4X对象。
  • int和uint是两个新的简单数字类型,分别针对整数和非负整数(正整数和0)。它们多被用在需要十进制数值的地方(例如循环步进值)。int类型可以用在大多数需要数字的地方,而uint类型只能用在诸如颜色值这类必要的地方。

==================================================

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.