# Getting resize height value of Autosize label

**URL:** https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290
**Category:** Uncategorized
**Created:** [July 7, 2008, 2:15pm UTC](https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290 "2008-07-07T14:15:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)
#### Post date: [July 7, 2008, 2:15pm UTC](https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290/1 "2008-07-07T14:15:36Z")

</div>

Have a wee problem here:

I’ve got a fuction that’s looped and creates numerous labels - I want to get the height of each so I can place them neatly below one another. I’m using a listener to get the ‘dynamic height’ of the label created but am having problems returning the value to the addTextRP to use - any ideas?

```auto
 
  public function addTextRP(thisText:String, i:Number):void {
   var lblFld:Label = new Label();
   lblFld.x=0;
   lblFld.width = 160;
   lblFld.wordWrap=true;
   lblFld.autoSize = TextFieldAutoSize.CENTER;
   lblFld.y=txtHeight;
   lblFld.name = "txtFld" + i;
   lblFld.text=thisText;
   lblFld.addEventListener(ComponentEvent.RESIZE, resizeHandler);
   addChild(lblFld);
   var thisHeight:Number = txtFld.height; [COLOR=red]// doesn't get the right height[/COLOR]
}

```

```auto
 
  function resizeHandler(event:ComponentEvent):Number {
   var lbl:Label = event.currentTarget as Label;
   trace("width:" + lbl.width, "height:" + lbl.height);[COLOR=red] // this traces the correct heights[/COLOR]
   return(lbl.height);
  }

```

Any help would be fantastic!

Many thanks,

partimer

---

<div class="post-metadata">

### Author: ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)
#### Post date: [July 7, 2008, 2:21pm UTC](https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290/2 "2008-07-07T14:21:10Z")

</div>

I’m a bit confused;

```auto

public function addTextRP(thisText:String, i:Number):void {
   var lblFld:Label = new Label();
   lblFld.x=0;
   lblFld.width = 160;
   lblFld.wordWrap=true;
   lblFld.autoSize = TextFieldAutoSize.CENTER;
   lblFld.y=txtHeight;
   lblFld.name = "txtFld" + i;
   lblFld.text=thisText;
   lblFld.addEventListener(ComponentEvent.RESIZE, resizeHandler);
   addChild(lblFld);
   var thisHeight:Number = txtFld.height; // doesn't get the right height
}

```

You say it’s not getting the right height? That’s not really surprising since ‘txtFld’ doesn’t exist anywhere there… should probably be lblFld.height no?

---

<div class="post-metadata">

### Author: ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)
#### Post date: [July 7, 2008, 2:25pm UTC](https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290/3 "2008-07-07T14:25:02Z")

</div>

You’re absolutely right - all references should be to lblFld. I have them named here as txtFld and replaced them posting it here (for a bit of legibility) but obviously missed out that occurence. Apols for the confusion.

---

<div class="post-metadata">

### Author: ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)
#### Post date: [July 7, 2008, 2:26pm UTC](https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290/4 "2008-07-07T14:26:14Z")

</div>

Can you show the label class ? Is it just straight extending textfield?

---

<div class="post-metadata">

### Author: ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)
#### Post date: [July 7, 2008, 2:32pm UTC](https://forum.kirupa.com/t/getting-resize-height-value-of-autosize-label/265290/5 "2008-07-07T14:32:37Z")

</div>

Here’s where I get a little embarressed about how messy my code is (still getting used to it) but:

```auto
package {	

  import flash.events.MouseEvent;
  import flash.display.*;
  import flash.events.*;
  import flash.net.*;
  import flash.utils.*;
  import flash.text.TextField;
  import fl.controls.TextArea;
  import fl.controls.Label;
  import flash.text.TextFieldAutoSize;
  import fl.events.ComponentEvent;

	public class MainStart extends Sprite{

		internal var thisNumber:Number = 1000;			
		public var rightPanel1:Sprite = new rightPanel();		
		public var rightPanel2:Sprite = new rightPanel();				
		public var rpButton1:Sprite = new rpButton();	
		public var rpButton2:Sprite = new rpButton();	

	var xmlLoader:URLLoader = new URLLoader();
			xmlLoader.addEventListener(Event.COMPLETE, showXML);
			xmlLoader.load(new URLRequest("loadClient.xml"));
			function showXML(e:Event):void {
				XML.ignoreWhitespace = true; 
				var songs:XML = new XML(e.target.data);
				trace(songs.track.length());
				var i:Number;
				for (i=0; i < songs.track.length(); i++) {
					
					addTextRP(songs.track*.band.text(), i);

				}
			}

		}
		
		public function addTextRP(thisText:String, i:Number):void {
			var thisNewNum:Number=0;
			var lblFld:Label = new Label();
			lblFld.x=0;
			lblFld.width = 160;
			lblFld.wordWrap=true;
			lblFld.autoSize = TextFieldAutoSize.CENTER;
			lblFld.y=txtHeight;
			lblFld.name = "lblFld" + i;
			lblFld.text=thisText;
			lblFld.addEventListener(ComponentEvent.RESIZE, resizeHandler());
			addChild(lblFld);

			var thisHeight:Number = lblFld.height;
			
			lblFld.addEventListenerMouseEvent.MOUSE_OVER,highlightText);
			lblFld.addEventListenerMouseEvent.MOUSE_OUT,unhighlightText);
			lblFld.addEventListener(MouseEvent.MOUSE_DOWN,dragHighlightText);	
[INDENT][/INDENT]}

		function resizeHandler(event:ComponentEvent):Number {
			var lbl:Label = event.currentTarget as Label;
			trace("width:" + lbl.width, "height:" + lbl.height);
			return(lbl.height);
		}

```
