Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 235
Registered: ‎12-13-2011
My Device: Curve 9380
My Carrier: Vodafone-IN
Accepted Solution

How to autosize the textField??

hai..

        I am trying to get string from xml file each of the string have different in length.. I need to set the height of textfield automatically. Anybody knows the idea about that please help me.

 

Thanks

Deepu

Developer
Posts: 116
Registered: ‎11-18-2010
My Device: BlackBerry PlayBook
My Carrier: null

Re: How to autosize the textField??

Can You please provide an example of the code You have using?
Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: How to autosize the textField??

Can you post some code? Did you try using the autoSize property?

 

import flash.text.TextField;
import flash.text.TextFieldAutoSize;

var result:TextField = new TextField();
result.autoSize=TextFieldAutoSize.LEFT;

 

 

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 116
Registered: ‎11-18-2010
My Device: BlackBerry PlayBook
My Carrier: null

Re: How to autosize the textField??

Here is a quick example to You:

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class PlayBook_TextField extends Sprite
	{
		public function PlayBook_TextField()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			// Create an array of the random lenghts strings
			var textStringsArray:Array = new Array(5);
			textStringsArray[0] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
			textStringsArray[1] = "Donec id tellus nibh, vitae rhoncus enim. Ut porttitor pulvinar semper. ";
			textStringsArray[2] = "Fusce eu leo magna, sed imperdiet tortor. Sed vestibulum, massa id ornare iaculis, metus purus laoreet est, id volutpat urna justo auctor orci.";
			textStringsArray[3] = "Aenean tristique convallis felis, vitae placerat massa aliquam at.";
			textStringsArray[4] = "Nullam bibendum turpis vitae nisl hendrerit in condimentum ipsum ornare. Maecenas bibendum, erat a convallis varius, mi est posuere ligula, in blandit diam ante non diam.";
			
			var textField:TextField;
			var lastTextField_Height:int;
			var lastTextField_Y:int;
			
			var textFormat:TextFormat = new TextFormat;
			textFormat.size = 20;
			
			// Create a text fields
			for (var i:int; i < textStringsArray.length; i++) {
				textField = new TextField();
				textField.autoSize = TextFieldAutoSize.LEFT;
				
				textField.multiline = true;
				textField.wordWrap = true;
				textField.htmlText = textStringsArray[i];
				
				// this is optional - in order to get a bigger text size
				textField.setTextFormat(textFormat);
				
				// Apply a custom width to the textField or it's gonna be default
				textField.width = 300;
				// Apply a correct height to the textField
				textField.height = textField.textHeight + 10;
				
				textField.y = lastTextField_Y + lastTextField_Height + 20;
				addChild(textField);
				
				lastTextField_Y = textField.y;
				lastTextField_Height = textField.height;
			}
		}
	}
}

 

Developer
Posts: 235
Registered: ‎12-13-2011
My Device: Curve 9380
My Carrier: Vodafone-IN

Re: How to autosize the textField??

Thanks