[1b]Class scope is now bound to class methods[/1b]
[1b]类作用域现在和类方法绑定在一起了[/1b]
ActionScript 3 is entirely class-based.
ActionScript 3 是一个完全基于类的语言。
When you create classes, you create variables and functions (methods) which relate to and work with that class and instances of that class.
当你创建类的时候,你除了创建这个类的实例外,同时也创建了和这个类相关的变量和方法。
Unlike ActionScript 2, methods in ActionScript 3 now retain their class scope when called, even if assigned to another object and called from that object, or if used with Function.call and Function.apply.
和ActionScript 2不同,在ActionScript 3中的类中的方法的作用域仍然保留在这个类里面,而不管是不是其他的类调用这个方法。可能有点难以明白,看代码吧(即使看了代码也不明白的)
大概就是想说保持this的指向吧
Example:
代码:
package {
import flash.display.Sprite;
public [1b]class[/1b] ClassScope extends Sprite {
public [1b]function[/1b] ClassScope() {
traceThis(); //输出: "Class Instance"
[1b]var[/1b] obj:Object = [1b]new[/1b] Object();
obj.traceThis = traceThis;
obj.traceThis(); //
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/1808.html