tags:

views:

47

answers:

3

Is there a way to prevent a component from rendering in Flex (to save memory or processing power)?

I tried doing something like:

<components:AddNewItemGroup id="addItemGroup" 
            visible="false"
            enabled="false"
            horizontalCenter="0" bottom="0" />

I noticed that the component gets rendered but it's just not visible or functional.

A: 

How about setting "includeInLayout='false'" too ? The doc says it will not draw the component ... but maybe it will still "render" it ...

http://livedocs.adobe.com/flex/3/html/help.html?content=size_position_4.html

phtrivier
Setting that to false will still render the component:`If false, the object is positioned by its parent container as per its layout rules, but it is ignored for the purpose of computing the position of the next child.`http://livedocs.adobe.com/flex/3/langref/mx/core/UIComponent.html#includeInLayout
Wesley Petrowski
I agree, I was wondering about the combination of both visible=false and includeInLayout=false.
phtrivier
+1  A: 

If you want to prevent a component from being rendered, you need to remove it from the display list using the removeChild method in Actionscript.

Wesley Petrowski
I tried the following: AS: itemsGroupContainer.removeChild(addItemGroup); MXML: <s:Group id="itemsGroupContainer"><components:AddNewItemGroup id="addItemGroup" horizontalCenter="0" bottom="0" /></s:Group> But it didn't seem to work! Also where should I put the ActionScript code? if I put it in 'creationComplete' event of the component it wouldn't do what I want as it will render the item and then remove it.
Tam
ended up using addElement instead and it seems to work as opposed to addChild maybe it's because I'm using Flex 4
Tam
A: 

For the desired effect, use:

<components:AddNewItemGroup id="addItemGroup" visible="false" includeInLayout="false" enabled="false" horizontalCenter="0" bottom="0" />

Saheed