Doing it in the 'initialize' event seems like the right way to do it. The 
'initialize' event still occurs before the LayoutManager has sized and 
positioned the children. But if you wait until creationComplete() the 
LayoutManager has already laid out the children and calling setStyle()will 
force another layout.

Gordon Smith, Adobe

From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf 
Of flexwdw
Sent: Wednesday, April 11, 2012 3:40 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] setStyle, preinitialize and initialize



So, I've run into this before but I don't recall it being the headscratcher it 
has become today....

I'm using Flex 3.5 in an app. I have an MXML class with a bunch of UI in it. I 
have been asked to add a switch that causes the positions of some of the 
different child components to change. The components use constraint-based 
layouts, so this is going to amount to modifying their left, right, top, and 
bottom styles. This only needs to happen once per object creation.

In the docs:
http://livedocs.adobe.com/flex/3/html/help.html?content=styles_08.html

"Some applications must call the setStyle() method during the application or 
object instantiation. If this is the case, call the setStyle() method early in 
the instantiation phase. Early in the instantiation phase means setting styles 
from the component or application's preinitialize event, instead of the 
creationComplete or other event. By setting the styles as early as possible 
during initialization, you avoid unnecessary style notification and lookup. For 
more information about the component startup life cycle, see Improving Startup 
Performance."

Putting these style sets in preinitialize is impossible because the children 
have not been setup and are null. At this point, I am making the calls in the 
handler for the initialize event. Is there an acceptable way to do this without 
having to create two versions of the class subclass the children?

Reply via email to