Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable addChild is not defined?

i have a problem using AS3 - Flash CS3 gives me this Error message: Error #1065: Variable addChild 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;
        }
    }    
}
like image 570
Dungeo Avatar asked Dec 05 '25 15:12

Dungeo


1 Answers

It's because SimpleButton does not inherit from DisplayObjectContainer but from InteractiveObject.

addChild is a method from DisplayObjectContainer. SimpleButton contains 3 displayobject for the 3 states and the hittest object, they are named upState, overState, downState and hitTestState.

So you should be able to set one of them.

//addChild(result);
upState = result;

You could just add a DisplayObjectContainer (like a Sprite) to the states and then add the TextField there instead, in case you want to add more graphics to the states.

upState = new Sprite();
upState.addChild(new MyButtonBackground()); //Make this class.
upState.addChild(result);
like image 139
Jacob Poul Richardt Avatar answered Dec 08 '25 06:12

Jacob Poul Richardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!