Useful Flex Tip: Use CallLater()
Submitted by jrowny on Wed, 10/22/2008 - 07:00
Have you ever tried to do something like this:
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);
}
ahhh... there we go. 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.
Bookmark/Search this post with:
Recent comments
1 week 3 days ago
2 weeks 2 days ago
2 weeks 2 days ago
11 weeks 6 days ago
12 weeks 1 day ago
12 weeks 1 day ago
14 weeks 8 hours ago
19 weeks 2 days ago
28 weeks 2 days ago
34 weeks 5 hours ago