3

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;
        }
    }    
}
Dungeo
  • 177
  • 2
  • 7
  • 16

1 Answers1

5

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);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jacob Poul Richardt
  • 3,145
  • 1
  • 26
  • 29