Wrap it inside an <mx:Object> tag as in the following example:
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical">
        <mx:Button label="Test" click="trace('instantiated: ' +
(textDeferred.parent ? 'Yes' : 'No'))" />
        <mx:Button label="Instantiate" click="if (textDeferred.parent ==
null) addChild(textDeferred);" />
        <mx:Object>
                <mx:content>
                        <mx:Label id="textDeferred" text="Here I am!" />
                </mx:content>           
        </mx:Object>
</mx:Application>


Note that the property name "mx:content" doesn't matter, it can be anything,
just needs to be something so the content gets assigned to a property of the
object.

If you're going to do this a lot it would be cleaner to create your own
class that defines a default property, say DontInstantiate, then you do
something like:

<DontInstantiate>
  <mx:Label ... />
</DontInstantiate>

And the end result is the same but is easier to understand what's going on.
You'll need to define a default property in order to put your nested content
directly inside the nested class.

HTH,

Sam


-------------------------------------------
We're Hiring! Seeking a passionate developer to join our team building Flex
based products. Position is in the Washington D.C. metro area. If interested
contact [EMAIL PROTECTED]

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Mark Ingram
Sent: Thursday, October 25, 2007 5:29 AM
To: [email protected]
Subject: [flexcoders] Add reference in MXML without adding to children

Hi, does anyone know if it's possible to create a reference in MXML (so that
you can later use it as a variable and also easily use bindings) but not add
it to the parent's children?

i.e.

<mx:Canvas>
            <mx:Script>
            Private function someEvent()
            {
                        PopUpManager.addPopUp(titleWindow);
            }

            </mx:Script>
            <mx:TitleWindow/>
</mx:Canvas>

I don't want the title window to be shown inside the canvas, I just want to
create it as a variable.

Thanks,

Mark

Reply via email to