AS2:类不工作

发布于 2024-11-17 23:34:08 字数 1258 浏览 1 评论 0原文

到目前为止,这是我的课程:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2024-11-24 23:34:08

您对 createEmptyMovieClip 的调用失败,因为没有可以创建影片剪辑的舞台。考虑这个简单的示例,说明如何在不将类附加到库项的情况下执行此操作:

类:

class MyMenu extends MovieClip {

    public var titleField:MovieClip;

    public function MyMenu($target:MovieClip) {
        this.titleField = createTitleBar($target);
    }

    public function createTitleBar($target:MovieClip):MovieClip {
        var titleBar = $target.createEmptyMovieClip("titleBar", 1);
        return titleBar;
    }
}

IDE:

import MyMenu;
var menu:MyMenu = new MyMenu(this);
trace(menu.titleField);

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:

class MyMenu extends MovieClip {

    public var titleField:MovieClip;

    public function MyMenu($target:MovieClip) {
        this.titleField = createTitleBar($target);
    }

    public function createTitleBar($target:MovieClip):MovieClip {
        var titleBar = $target.createEmptyMovieClip("titleBar", 1);
        return titleBar;
    }
}

IDE:

import MyMenu;
var menu:MyMenu = new MyMenu(this);
trace(menu.titleField);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文