tags:

views:

9

answers:

1

I have some MXML elements which i would like to remove and add to a parent element. Unfortunately I am constrained to removing the MXML object as this is handled by the custom component. So is there any way to reinstate a removed MXML element back into the display list?

Sorry if this is an old question, or am i missing something obvious.

A

A: 

You have to store a reference to the component as a variable somehow.

var myComponent : UIComponent = mxmlID
this.removeChild(myComponent)

Then at some future point you can do this:

this.addChild(myComponent);

Nothing about using custom components should affect this at all. I'm unclear what happens behind the scenes with MXML set IDs that are removed; but I assume they are garbage collected and you won't be able to access the same component w/ the same ID.

www.Flextras.com
What's the need to store in a separate variable? Wouldn't just `this.removeChild(mxmlId);` work as well? `mxmlId` would continue to be a public variable and be accessible even if it is removeChild'ed.
Amarghosh
of course!! why didn't I check this? The mxmlid does still exist.Anyway, thanks for your help!
Alex
removeChild(mxmlID) should work fine. I just wasn't sure you'd be able to add it back in. IT sounds like it worked for you. To find out what really goes on, use the "-keep" compiler argument and review the ActionScript. Does addChild(mxmlID) create a new instance? Or is the old instance kept around?
www.Flextras.com