Is addChild variable undefined?

I have a problem with AS3 - Flash CS3 gives me this error message: Error # 1065: addChild variable is not defined.

Any ideas what's wrong?

This is my code:

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;
        }
    }    
}
+3
source share
1 answer

This is because SimpleButton is not inherited from DisplayObjectContainer, but from InteractiveObject.

addChild is a method from DisplayObjectContainer. SimpleButton contains 3 displayobjects for three states and a hittest, they are called upState, overState, downState and hitTestState.

So, you must install one of them.

//addChild(result);
upState = result;

DisplayObjectContainer (, Sprite) , TextField, .

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

Source: https://habr.com/ru/post/1706034/


All Articles