【问题标题】:Variable addChild is not defined?变量 addChild 没有定义?
【发布时间】:2010-10-18 00:43:57
【问题描述】:

我在使用 AS3 时遇到问题 - Flash CS3 向我显示以下错误消息:错误 #1065:未定义变量 addChild。

有什么想法吗?

这是我的代码:

package coa.application{
    import flash.display.SimpleButton;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class Tab extends SimpleButton {

        public var menuType:String;

        public function Tab(tabText:String, menuType:String) {
            this.menuType=menuType;
            var mytext:TextField=createTextField(0,0,200,20);
            mytext.text=tabText;
        }
        private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x=x;
            result.y=y;
            result.width=width;
            result.height=height;
            addChild(result);
            return result;
        }
    }    
}

【问题讨论】:

    标签: actionscript-3 flash-cs3 addchild


    【解决方案1】:

    这是因为 SimpleButton 不是继承自 DisplayObjectContainer 而是继承自 InteractiveObject。

    addChild 是来自 DisplayObjectContainer 的方法。 SimpleButton 包含 3 个显示对象,分别代表 3 个状态和 hittest 对象,它们分别命名为 upState、overState、downState 和 hitTestState。

    所以你应该可以设置其中之一。

    //addChild(result);
    upState = result;
    

    您可以只向状态添加一个 DisplayObjectContainer(如 Sprite),然后在其中添加 TextField,以防您想向状态添加更多图形。

    upState = new Sprite();
    upState.addChild(new MyButtonBackground()); //Make this class.
    upState.addChild(result);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 2011-04-17
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多