学习AS3:唯一的类变量-Flash教程
来源: 作者:
更新时间:2008-03-04
点击:
(本文非直接翻译,原文如下:)
In ActionScript 2, variables defined within a class's body were defined in the class's prototype object. This was an efficient means to handle variable definitions but it also meant that complex data types (such as Arrays) had a tendency to be \"shared\" among instances if not explicitly defined for instances within the class constructor. This is no longer a problem with ActionScript 3. Class variables defined in the class body are now unique to each class instance so this problem no longer occurs.
在AS2中,复杂数据类型(比如数组),假如在类体之中,方法之外直接初始化,而不在构造器中初始化,会被理解为“共享”的数据,而被所有的实例共享使用(类似于static的效果)。但是在AS3中不存在这个问题。类变量是每个实例独有的,唯一的变量。如下:
class myClass{
private var list:Array = [1,2,3]; //在AS2中会有一定问题,AS3中就很好
public function myClass(){
//在AS2中,应该在这里初始化list
}
}
In ActionScript 2, variables defined within a class's body were defined in the class's prototype object. This was an efficient means to handle variable definitions but it also meant that complex data types (such as Arrays) had a tendency to be \"shared\" among instances if not explicitly defined for instances within the class constructor. This is no longer a problem with ActionScript 3. Class variables defined in the class body are now unique to each class instance so this problem no longer occurs.
在AS2中,复杂数据类型(比如数组),假如在类体之中,方法之外直接初始化,而不在构造器中初始化,会被理解为“共享”的数据,而被所有的实例共享使用(类似于static的效果)。但是在AS3中不存在这个问题。类变量是每个实例独有的,唯一的变量。如下:
class myClass{
private var list:Array = [1,2,3]; //在AS2中会有一定问题,AS3中就很好
public function myClass(){
//在AS2中,应该在这里初始化list
}
}
相关Flash教程:
最新评论:
评论加载中....
发表评论:不能超过250字节,请自觉遵守互联网相关政策法规.
- 昵称: 验证:







