joebox
asked on
How to get actionscript generated component to update its properties
Oh man I am obviously missing something here but not sure what it is. How can I get the HBox to update its width after an addChild(). I am tracing our the width before and after the addChild but it doesnt change.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Label;
import mx.containers.HBox;
private function init():void {
var row:HBox = new HBox();
var txt:Label = new Label();
txt.text = "just some text";
trace(row.width.toString());
row.addChild(txt);
trace(row.width.toString());
}
]]>
</mx:Script>
</mx:Application>
ASKER
thanks for the tip but it didn't bring any luck. Both traces are still coming up as 0. Here is the updated code that i ran.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Label;
import mx.containers.HBox;
private function init():void {
var row:HBox = new HBox();
this.addChild(row);
var txt:Label = new Label();
txt.text = "just some text";
trace(row.width.toString());
row.invalidateDisplayList();
row.invalidateSize();
row.addChild(txt);
trace(row.width.toString());
}
]]>
</mx:Script>
</mx:Application>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Sorry took so long to get back to you. You rock for helping out. Your solution does work I just wanted to ask you one more thing about it. Is there any way to get the length of the string before you add it to the container.
var txt:Label = new Label();
txt.text = "just some text";
txt.validateNow():
trace(txt.measuredWidth);
this doesnt work.
.
var txt:Label = new Label();
txt.text = "just some text";
txt.validateNow():
trace(txt.measuredWidth);
this doesnt work.
.
Check out
http://livedocs.adobe.com/labs/air/1/aslr/flash/text/TextLineMetrics.html
http://blog.greensock.com/textmetrics/
From my experience these classes don't bother measuring themselves until they are added to the display list.
http://livedocs.adobe.com/labs/air/1/aslr/flash/text/TextLineMetrics.html
http://blog.greensock.com/textmetrics/
From my experience these classes don't bother measuring themselves until they are added to the display list.
ASKER
hey I thank you very very much for all your help.
Open in new window