Using the callLater method in flex, lazy calling in flex

Hi All,

The callLater() method queues an operation to be performed for the next screen refresh, rather than in the current update. Without the callLater() method, you might try to access a property of a component that is not yet available. The callLater() method is most commonly used with the creationComplete event to ensure that a component has finished being created before Flex proceeds with a specified method call on that component.

var someText:Text = new Text();
someText.text=”testing”;
addChild(someText);
trace(someText.measuredWidth);

and then scratched your head when Flex traces 0 for the width? That’s because Flex hasn’t drawn it yet. There’s two ways to fix it, one you could just call someText.validateSize() but the better way to do it is to wait till Flex validates on its own to make these changes. How do you do that? Well with the callLater() function of course!

var someText:Text = new Text();
someText.text=”testing”;
addChild(someText);
callLater(getWidth);
public function getWidth():void{
trace(someText.measuredWidth);
}

Now Flex should be tracing the correct width. This works really well for a number of instances where you want to play with freshly declared visual elements but Flex hasn’t finished creating them yet.

Sources[http://www.jonathanrowny.com/journal/useful-flex-tip-use-calllater, http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_12.html%5D

Thanks
R Vashi

One thought on “Using the callLater method in flex, lazy calling in flex

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s