AS2:上课不工作

时间:2011-07-01 14:20:23

标签: flash actionscript actionscript-2

到目前为止,这是我的班级:

 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);

由于

1 个答案:

答案 0 :(得分:1)

您对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);