<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Dynamically adding new children to a Flex Accordion container</title>
	<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Sat, 11 Oct 2008 21:02:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-15981</link>
		<author>peterd</author>
		<pubDate>Fri, 03 Oct 2008 06:25:50 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-15981</guid>
		<description>Kirk,

The same general code should work for TabNavigator:
&lt;pre class="code"&gt;
&#60;?xml version="1.0" encoding="utf-8"?&#62;
&#60;mx:Application name="TabNavigator_addChild_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&#62;

    &#60;mx:Script&#62;
        &#60;![CDATA[
            import mx.containers.HBox;

            private function addChildButton_click(evt:MouseEvent):void {
                var box:HBox = new HBox();
                box.label = "Child " + tabNavigator.numChildren;
                box.percentWidth = 100;
                box.percentHeight = 100;
                box.setStyle("backgroundColor", int(Math.random() * 0xFFFFFF));
                tabNavigator.addChild(box);
            }

            private function removeChildButton_click(evt:MouseEvent):void {
                if (tabNavigator.selectedChild != null) {
                    tabNavigator.removeChild(tabNavigator.selectedChild);
                }
            }
            
            private function removeAllChildrenButton_click(evt:MouseEvent):void {
                tabNavigator.removeAllChildren();
            }
        ]]&#62;
    &#60;/mx:Script&#62;

    &#60;mx:ApplicationControlBar dock="true"&#62;
        &#60;mx:Button id="addChildButton"
                label="Add child"
                click="addChildButton_click(event);" /&#62;
        &#60;mx:Button id="removeChildButton"
                label="Remove child"
                click="removeChildButton_click(event);" /&#62;
        &#60;mx:Button id="removeAllChildrenButton"
                label="Remove all children"
                click="removeAllChildrenButton_click(event);" /&#62;
    &#60;/mx:ApplicationControlBar&#62;

    &#60;mx:TabNavigator id="tabNavigator"
            width="100%"
            height="100%" /&#62;

&#60;/mx:Application&#62;
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>Kirk,</p>
<p>The same general code should work for TabNavigator:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application name="TabNavigator_addChild_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.containers.HBox;

            private function addChildButton_click(evt:MouseEvent):void {
                var box:HBox = new HBox();
                box.label = "Child " + tabNavigator.numChildren;
                box.percentWidth = 100;
                box.percentHeight = 100;
                box.setStyle("backgroundColor", int(Math.random() * 0xFFFFFF));
                tabNavigator.addChild(box);
            }

            private function removeChildButton_click(evt:MouseEvent):void {
                if (tabNavigator.selectedChild != null) {
                    tabNavigator.removeChild(tabNavigator.selectedChild);
                }
            }

            private function removeAllChildrenButton_click(evt:MouseEvent):void {
                tabNavigator.removeAllChildren();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button id="addChildButton"
                label="Add child"
                click="addChildButton_click(event);" /&gt;
        &lt;mx:Button id="removeChildButton"
                label="Remove child"
                click="removeChildButton_click(event);" /&gt;
        &lt;mx:Button id="removeAllChildrenButton"
                label="Remove all children"
                click="removeAllChildrenButton_click(event);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:TabNavigator id="tabNavigator"
            width="100%"
            height="100%" /&gt;

&lt;/mx:Application&gt;
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-15976</link>
		<author>Kirk</author>
		<pubDate>Thu, 02 Oct 2008 22:07:56 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-15976</guid>
		<description>Paul:

Will the same code work to dynamically add a tab to a tabnavigator container?

Kirk</description>
		<content:encoded><![CDATA[<p>Paul:</p>
<p>Will the same code work to dynamically add a tab to a tabnavigator container?</p>
<p>Kirk</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-7447</link>
		<author>peterd</author>
		<pubDate>Mon, 10 Mar 2008 05:32:40 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-7447</guid>
		<description>PaulH,

Apart from setting the &lt;code&gt;creationPolicy&lt;/code&gt; property, I don't have any other immediate ideas. And you tried setting the &lt;code&gt;creationPolicy&lt;/code&gt; to "all", or setting it to "auto" then "all"?

If you think it is a bug, file it at http://bugs.adobe.com/flex/ and solicit a few votes and then somebody at Adobe can take a look.

Peter</description>
		<content:encoded><![CDATA[<p>PaulH,</p>
<p>Apart from setting the <code>creationPolicy</code> property, I don&#8217;t have any other immediate ideas. And you tried setting the <code>creationPolicy</code> to &#8220;all&#8221;, or setting it to &#8220;auto&#8221; then &#8220;all&#8221;?</p>
<p>If you think it is a bug, file it at <a href="http://bugs.adobe.com/flex/" rel="nofollow">http://bugs.adobe.com/flex/</a> and solicit a few votes and then somebody at Adobe can take a look.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PaulH</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-7436</link>
		<author>PaulH</author>
		<pubDate>Mon, 10 Mar 2008 01:42:30 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-7436</guid>
		<description>peter, 

what about the contents of the remaining children? i've got an accordion setup in mxml that i reconfigure by deleting children. what i'm seeing is the contents of the remaining children (all List) aren't getting rendered until the user changes the selectedIndex. i've tried pretty much all the tricks i know to get the List contents to render after deleting the child (creationPolicy, etc.) but no luck.

any ideas?

ps: i guess no need to keep repeating how much we love this blog, but what the heck, "we love this blog" ;-)</description>
		<content:encoded><![CDATA[<p>peter, </p>
<p>what about the contents of the remaining children? i&#8217;ve got an accordion setup in mxml that i reconfigure by deleting children. what i&#8217;m seeing is the contents of the remaining children (all List) aren&#8217;t getting rendered until the user changes the selectedIndex. i&#8217;ve tried pretty much all the tricks i know to get the List contents to render after deleting the child (creationPolicy, etc.) but no luck.</p>
<p>any ideas?</p>
<p>ps: i guess no need to keep repeating how much we love this blog, but what the heck, &#8220;we love this blog&#8221; ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: djrogi</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-7266</link>
		<author>djrogi</author>
		<pubDate>Sat, 01 Mar 2008 07:34:01 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-7266</guid>
		<description>on a dynamically created accordion like this, how would you create a DataGrid that pulls from live data?  Been working on it for about 3 days now, and get stumped by adding a child under a child.

Awesome examples they are a huge help to new Flex-ers</description>
		<content:encoded><![CDATA[<p>on a dynamically created accordion like this, how would you create a DataGrid that pulls from live data?  Been working on it for about 3 days now, and get stumped by adding a child under a child.</p>
<p>Awesome examples they are a huge help to new Flex-ers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: danny</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-5130</link>
		<author>danny</author>
		<pubDate>Sat, 15 Dec 2007 22:35:54 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-5130</guid>
		<description>hey, what if I wanted to put the add and remove functions into there own class? when i do that, it says that "accordian.addchild..." is undefined. I'm trying to learn how to make my code more modular, and if someone could explain this it would be very helpful. thanks!</description>
		<content:encoded><![CDATA[<p>hey, what if I wanted to put the add and remove functions into there own class? when i do that, it says that &#8220;accordian.addchild&#8230;&#8221; is undefined. I&#8217;m trying to learn how to make my code more modular, and if someone could explain this it would be very helpful. thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samus_</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3971</link>
		<author>Samus_</author>
		<pubDate>Thu, 08 Nov 2007 01:14:40 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3971</guid>
		<description>UPDATE: I've checked again that link and the links suggested there, there is a way to add the listeners as "weak references" that are ignored by the garbage collector; very interesting, that solves half of my problem of lost references.
check it here: http://www.adobe.com/devnet/flashplayer/articles/resource_management.html and here: http://www.gskinner.com/blog/archives/2006/07/as3_weakly_refe.html</description>
		<content:encoded><![CDATA[<p>UPDATE: I&#8217;ve checked again that link and the links suggested there, there is a way to add the listeners as &#8220;weak references&#8221; that are ignored by the garbage collector; very interesting, that solves half of my problem of lost references.<br />
check it here: <a href="http://www.adobe.com/devnet/flashplayer/articles/resource_management.html" rel="nofollow">http://www.adobe.com/devnet/flashplayer/articles/resource_management.html</a> and here: <a href="http://www.gskinner.com/blog/archives/2006/07/as3_weakly_refe.html" rel="nofollow">http://www.gskinner.com/blog/archives/2006/07/as3_weakly_refe.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samus_</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3970</link>
		<author>Samus_</author>
		<pubDate>Thu, 08 Nov 2007 00:27:13 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3970</guid>
		<description>hi thanks for the reply! yes reading a little more seems that objects are destroyed when there's no other reference to them, that reminds me of files in a unix filesystem; is quite tricky to me honestly I didn't expected something like that because this forces me to keep track of references to the objects and it seems that event listeners also apply as references, perhaps you could suggest me some design patterns that are better to deal with this situation (I'm more used to the C approach and never worked in Java). I'm most worried about leaking memory because I left some references somewhere else :/ also I've found an interesting article about the garbage collectos itself here: http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html c'ya!</description>
		<content:encoded><![CDATA[<p>hi thanks for the reply! yes reading a little more seems that objects are destroyed when there&#8217;s no other reference to them, that reminds me of files in a unix filesystem; is quite tricky to me honestly I didn&#8217;t expected something like that because this forces me to keep track of references to the objects and it seems that event listeners also apply as references, perhaps you could suggest me some design patterns that are better to deal with this situation (I&#8217;m more used to the C approach and never worked in Java). I&#8217;m most worried about leaking memory because I left some references somewhere else :/ also I&#8217;ve found an interesting article about the garbage collectos itself here: <a href="http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html" rel="nofollow">http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html</a> c&#8217;ya!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samuel Neff</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3822</link>
		<author>Samuel Neff</author>
		<pubDate>Sat, 03 Nov 2007 04:10:59 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3822</guid>
		<description>Samus,

The component is destroyed just like any other class--when it is not accessible from the application (when all references are destroyed).  Having a parent is a reference so being on the display list by definition keeps something alive.  Having a reference to the component such as an instance variable also could keep it alive.

In the above example, however, the component is created as a function-local variable and added to the accordion.  No other reference is kept so in this situation, the component is eligible for garbage collection when it's removed from the display list.

HTH,

Sam</description>
		<content:encoded><![CDATA[<p>Samus,</p>
<p>The component is destroyed just like any other class&#8211;when it is not accessible from the application (when all references are destroyed).  Having a parent is a reference so being on the display list by definition keeps something alive.  Having a reference to the component such as an instance variable also could keep it alive.</p>
<p>In the above example, however, the component is created as a function-local variable and added to the accordion.  No other reference is kept so in this situation, the component is eligible for garbage collection when it&#8217;s removed from the display list.</p>
<p>HTH,</p>
<p>Sam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samus_</title>
		<link>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3355</link>
		<author>Samus_</author>
		<pubDate>Wed, 10 Oct 2007 18:38:50 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/18/dynamically-adding-new-children-to-a-flex-accordion-container/#comment-3355</guid>
		<description>hello, citing from http://livedocs.adobe.com/flex/201/langref/mx/states/RemoveChild.html

"The RemoveChild class removes a child display object, such as a component, from a container as part of a view state. The child is only removed from the display list, it is not deleted."

this will surely lead to memory leaking problems, and also forces me to reset the control's contents each time they're shown, how can I destroy a component?</description>
		<content:encoded><![CDATA[<p>hello, citing from <a href="http://livedocs.adobe.com/flex/201/langref/mx/states/RemoveChild.html" rel="nofollow">http://livedocs.adobe.com/flex/201/langref/mx/states/RemoveChild.html</a></p>
<p>&#8220;The RemoveChild class removes a child display object, such as a component, from a container as part of a view state. The child is only removed from the display list, it is not deleted.&#8221;</p>
<p>this will surely lead to memory leaking problems, and also forces me to reset the control&#8217;s contents each time they&#8217;re shown, how can I destroy a component?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
