I am writing a class that extends mx.core.UIComponent. In the constructor of this class, I would like to add a Button (spark.components.Button). However, creating a new Button object (such as var b:Button = new Button();) and then doing this.addChild(b) doesn’t work — no button is appearing. Is there any reason why a Button object can’t be added as a child?
Edit: Just to add, when I print out the children, it says that the Button object is a child, but the Button doesn’t show up.
Using
UIComponentdirectly, you aren’t getting the layout of the child handled for you; you would need to set the position and size of your child components manually (see docs).Consider using a
Group(orCanvas, if you’re still on MX components) to handle child layout. You can still add rendering inupdateDisplayList, just make sure you callsuper.updateDisplayList()as well.