Why I hate doLater and waiting a frame
The whole method of waiting a frame to allow other functions to complete never sat right with me. It just seems.. broken.
In the MX components, doLater is used a lot - a function for putting off execution of another function until the next frame.. usually to allow other child components to finish initializing before laying them out.
Personally I would have used a cascading series of events, where the child components dispatch an “Ok I’m ready” event. The parent component would listen for these and when all child components are ready, it does its stuff and dispatches its own “Ready” event.
I’d be interested to know what methods other people use to make sure that things like layout get executed in the right order.

December 20th, 2005 at 12:42 pm
I agree, it definitely smells like a hack. One of those leftover artifacts from the Flash timeline. As Nigel Pegg is quoted as saying, “If all else fails, wait another frame.”
December 20th, 2005 at 1:04 pm
Couldn’t agree more. Bubbled events are an obvious solution to this hack, and something I utilize over doLater as much as I can whilst still allowing for compatability with the v2 framework.
December 20th, 2005 at 4:04 pm
doLater is a hack. I don’t like it just as much as the next guy. I usually implement my own callbacks to avoid such trickery.
December 20th, 2005 at 4:55 pm
For MovieClip’s, use onLoad.
For Components, use onLoad, or for mx.core.View, use initLayout.
In Flex 1.5, use childrenCreated.
In Flex 2, use creationComplete.
December 20th, 2005 at 5:22 pm
I don’t think I ever said “if all else fails, wait another frame” (I think you might be thinking of Peldi.. and I got on his case about that). If you’re not making components, you should never need doLater. However, there are a couple of great times and places for doLater in building components… They have nothing to do with event bubbling or timelines or all that other random stuff you guys are citing (as Jester points out, we already have events for initialization even in V2). Since everyone here is an expert (especially, it seems, in identifying hacks), can anyone tell me what they are?
December 20th, 2005 at 6:15 pm
I think I came across this while extending mx.core.View. The idea that initLayout came one frame later than I expected messed up my thinking.
I ask for peoples opinions about this because I happen to be writing my own component framework, and its always nice to know that you’re going about things the right way
December 20th, 2005 at 7:18 pm
Nigel, I do believe I heard you say or at least quote that “if all else fails … ” in your Q&A session at the last edition of FlashForward in SF
In any case, I do use doLater quite a lot when doing v2 component development. As was rightly pointed out the components do have their init events and use it for dealing with component params.
December 21st, 2005 at 6:09 am
There is a need for doLater(or postponed execution) when making components. If working with MM v2 components, there is no way to avoid it.
February 22nd, 2006 at 3:24 pm
we need some help with actonscript and flash v2 component knowledge/expertise