AS2:类不工作
到目前为止,这是我的课程:
class com.RCN.Menu.Menu extends MovieClip {
public var title:String;
public var menuItems:Array;
public var titleField:MovieClip;
public function Menu(title:String, menuItems:Array, menuActions:Array) {
this.titleField = createTitleBar(title);
}
public function createTitleBar(title:String) {
var titleBar = createEmptyMovieClip("titleBar", 1);
var titleText = createTextField("titleText", this.getNextHighestDepth(), 10, 10, 100, 100);
titleText.text = title;
titleText.autoSize = true;
titleText.multiline = false;
titleText.wordWrap = false;
titleText.border = true;
titleText.background = 0xffffff;
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.size = 14.5;
format.bold = true;
format.align = "left";
titleText.setTextFormat(format);
return titleBar;
}
}
然而,在我的 SWF 中,当我运行以下代码时,我得到了未定义,任何人都可以看到为什么吗? (新课)
import com.RCN.Menu.Menu;
var Accountability:Menu = new Menu("hello",[a,b,c,d]);
trace(Accountability.titleField);
谢谢
here is my class so far:
class com.RCN.Menu.Menu extends MovieClip {
public var title:String;
public var menuItems:Array;
public var titleField:MovieClip;
public function Menu(title:String, menuItems:Array, menuActions:Array) {
this.titleField = createTitleBar(title);
}
public function createTitleBar(title:String) {
var titleBar = createEmptyMovieClip("titleBar", 1);
var titleText = createTextField("titleText", this.getNextHighestDepth(), 10, 10, 100, 100);
titleText.text = title;
titleText.autoSize = true;
titleText.multiline = false;
titleText.wordWrap = false;
titleText.border = true;
titleText.background = 0xffffff;
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.size = 14.5;
format.bold = true;
format.align = "left";
titleText.setTextFormat(format);
return titleBar;
}
}
Yet in my SWF when I run the following code I get undefined, can anyone see why? (new to classes)
import com.RCN.Menu.Menu;
var Accountability:Menu = new Menu("hello",[a,b,c,d]);
trace(Accountability.titleField);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对 createEmptyMovieClip 的调用失败,因为没有可以创建影片剪辑的舞台。考虑这个简单的示例,说明如何在不将类附加到库项的情况下执行此操作:
类:
IDE:
Your call to createEmptyMovieClip is failing because there is no stage to create a movieclip on. Consider this simple example of how to do this without attaching your class to a library item:
Class:
IDE: