2007年3月26日星期一

Class scope is now bound to class methods

Class scope is now bound to class methods

ActionScript 3 is entirely class-based. 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. Example:
ActionScript Code:

package {

import flash.display.Sprite;
public class ClassScope extends Sprite {
public function ClassScope() {
traceThis();
// "Class Instance"
var obj:
Object = new Object();
obj.
traceThis = traceThis;
obj.
traceThis(); // "Class Instance"
traceThis.
call(new Sprite()); // "Class Instance"
}

public override function toString():String {
return "Class Instance";
}
public function traceThis():void {
trace(this);
}
}
}

0 评论: