Do something like this in your custom component. Let me know how this works
for you.
package
{
[DefaultProperty("content")] // this tell the Canvas if you don't specify a
property to put the children here
public class MyComp extends Canvas
{
private var _content : Array; // this will hold the children, in your
example the Label
private var contentChange : Boolean = false;
private var myHBox : HBox;
public function set content( value : Array ) : void
{
_content = value;
contentChanged = true;
invalidateProperties();
}
public function get content() : Array
{
return _content;
}
override protected function createChildren() : void
{
super.createChilldren();
myHbox = new HBox(); // create your HBox here
}
override protected function commitProperties() : void
{
if ( contentChanged && myHbox)
{
contentChanged = false;
for each ( child : UIComponent in content )
{
myHbox.addChild( child ); // this will add the Label in your
example to the myHBox
}
}
}
.
.
.
}
}
----- Original Message -----
From: Joseph Abenhaim
To: [email protected]
Sent: Monday, January 28, 2008 3:39 PM
Subject: [flexcomponents] Adding child to component subchild
I was trying to find out ways to have a custom component addchild method be
overriden to instead of adding child to the component itself, at it to one
of it's child. Example below:
Lets say I have a custom component which extends Canvas, inside this
component, I have a Hbox container.
When I put this component in MXML I'm trying to have it like so:
<customComponent>
<label>
</customComponent>
I would like the label to actually be added to the hbox inside the canvas.
Any way to do this at all ?
Thanks.
--
Joseph Abenhaim
Sr. Software Engineer - Flex
AOL Personal Media