Solved

How to get actionscript generated component to update its properties

Posted on 2008-06-10
6
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:taus01
ID: 21749527
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
ID: 21749747
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
ID: 21757188

<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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:joebox
ID: 21777086
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
ID: 21778203
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
ID: 21778298
hey I thank you very very much for all your help.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
adobe air: a simple question 3 371
Refresh Image 2 30 954
AS3 parent function 3 679
Running Guacamole on port 80 5 292
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…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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