[英]AS3 accessing stage from class
Timeline code: 时间轴代码:
import as3.first;
first._this=this;
var str1:String='this is timeline';
Class code: 班级代码:
package as3 {
import flash.display.MovieClip;
public class first extends MovieClip {
public static var _this:Object;
trace(_this.str1);
}
}
Error message: 错误信息:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
TypeError:错误#1009:无法访问空对象引用的属性或方法。
Trying to wrap my mind around how classes work. 试图让我的头脑围绕类的工作方式。 Need to access timeline functions and variables from class.
需要从类访问时间轴函数和变量。 What am I doing wrong and how can I make this work?
我做错了什么,该如何做?
All in all what you are doing is somewhat weird. 总而言之,您正在做的事情有些奇怪。 May be, you just want a document class for your SWF root?
可能是,您只想要SWF根目录的文档类 ? You as well could add a class to any movieclip in your library: both ways grant you access to timeline.
您也可以将一个类添加到库中的任何动画片段 :两种方式均授予您访问时间轴的权限。
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.