来自 class 的 AS3 访问阶段
AS3 accessing stage from class
时间轴代码:
import as3.first;
first._this=this;
var str1:String='this is timeline';
Class代码:
package as3 {
import flash.display.MovieClip;
public class first extends MovieClip {
public static var _this:Object;
trace(_this.str1);
}
}
错误信息:
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
试图围绕 classes 的工作原理进行思考。需要从 class 访问时间轴函数和变量。我哪里做错了,我怎样才能让它发挥作用?
总而言之,你做的事情有点奇怪。可能是,您只想 a document class for your SWF root? You as well could add a class to any movieclip 在您的图书馆中:这两种方式都允许您访问时间线。
package as3
{
import flash.display.MovieClip;
public class first extends MovieClip
{
public static var _this:Object;
trace(_this.str1); // you may place code here... but consider this:
// this area is STATIC, the code here
// executes only once when class gets initialized,
// so, this happens BEFORE you assign first._this=this;
}
}
时间轴代码:
import as3.first;
first._this=this;
var str1:String='this is timeline';
Class代码:
package as3 {
import flash.display.MovieClip;
public class first extends MovieClip {
public static var _this:Object;
trace(_this.str1);
}
}
错误信息:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
试图围绕 classes 的工作原理进行思考。需要从 class 访问时间轴函数和变量。我哪里做错了,我怎样才能让它发挥作用?
总而言之,你做的事情有点奇怪。可能是,您只想 a document class for your SWF root? You as well could add a class to any movieclip 在您的图书馆中:这两种方式都允许您访问时间线。
package as3
{
import flash.display.MovieClip;
public class first extends MovieClip
{
public static var _this:Object;
trace(_this.str1); // you may place code here... but consider this:
// this area is STATIC, the code here
// executes only once when class gets initialized,
// so, this happens BEFORE you assign first._this=this;
}
}