Solved

How to get actionscript generated component to update its properties

Posted on 2008-06-10
6
548 Views
Last Modified: 2008-06-13
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>

Open in new window

0
Comment
Question by:joebox
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:taus01
Comment Utility
Try calling the one or both of following Methods before you add the child:

/* Marks a component so that its updateDisplayList() method gets called during a later screen update */

row.invalidateDisplayList();
 

/* Marks a component so that its measure() method gets called during a later screen update. */

row.invalidateSize();

Open in new window

0
 

Author Comment

by:joebox
Comment Utility
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>

Open in new window

0
 
LVL 19

Accepted Solution

by:
Gary Benade earned 500 total points
Comment Utility

<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";

				row.addChild( txt);

				trace(txt.measuredWidth);

				trace(row.measuredWidth);

				row.validateNow();

				trace(txt.measuredWidth);

				trace(row.measuredWidth);

			}	

		]]>

	</mx:Script>

</mx:Application>

Open in new window

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:joebox
Comment Utility
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.
.  
0
 
LVL 19

Expert Comment

by:Gary Benade
Comment Utility
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.
0
 

Author Comment

by:joebox
Comment Utility
hey I thank you very very much for all your help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now