What does your component extend? If you're extending a Container, you can only use addChild() to content children which implement the IUIComponent interface. In order to support the LayoutManager, a content child has to implement things like measure(), etc.

 

However you should able to add it as a non-content or "chrome" child by doing rawChildren.addChild(myButton). Non-content children don't undergo automatic sizing and layout, so you'll have to set the size and position of myButton yourself.

 

- Gordon

 


From: [email protected] [mailto:[email protected]] On Behalf Of Tom Bray
Sent: Tuesday, April 11, 2006 11:05 AM
To: [email protected]
Subject: [flexcoders] Flex2B2: cannot convert flash.display::SimpleButton to mx.core.IUIComponent

 

What do I need to do to add a SimpleButton to my component without getting the type coercion error above?  The code I'm using is taken directly from the docs and it's pasted below.  The parent component is an HBox.

...

        import flash.display.*;

        private function doInit():void
        {
             var myButton:SimpleButton = new SimpleButton();
             var downSprite:Sprite = new Sprite();
             downSprite.graphics.lineStyle(2, 0x202020);
             downSprite.graphics.beginFill(0x00FF00);
             downSprite.graphics.drawRect(10, 10, 50, 50);
             
             var upSprite:Sprite = new Sprite();
             upSprite.graphics.lineStyle(2, 0x202020);
             upSprite.graphics.beginFill(0xFFFF00);
             upSprite.graphics.drawRect(10, 10, 50, 50);
             
             myButton.upState = upSprite;
             myButton.overState = upSprite;
             myButton.downState = downSprite;
             myButton.useHandCursor = true;
             myButton.hitTestState = this;
             
             this.addChild( myButton );
}

...



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to