AutoSize Flex component for mobile components

I want my sparkarea mobile text to be all content. I learned the mx_internal way to do this, but I cannot call the mx_internal :: getTextField () method . NumLines - No such ... Anyone who has done this before?

+8
flex flex4 flex-mobile
source share
2 answers

Here is a solution for mobile devices:

for(var i:int=0; i < StyleableTextField(txt_genel.textDisplay).numLines; i++) { ta_height += StyleableTextField(txt_genel.textDisplay).getLineMetrics(i).height; } txt_genel.height = ta_height; 
+3
source share

Here's a solution with a small custom TextArea class, there are comments to explain a little more.

 package { import mx.events.FlexEvent; import spark.components.TextArea; import spark.components.supportClasses.StyleableStageText; import spark.events.TextOperationEvent; public class CustomTextArea extends TextArea { private var _lineNumber:int = 1; private var _padding:int; private var _minHeight:int; public function CustomTextArea() { super(); addEventListener(FlexEvent.CREATION_COMPLETE, function setBehaviour(event:FlexEvent):void { //minHeight to prevent textarea to be too small _minHeight = height; //padding between textarea and text component inside to calculate line number _padding = ((textDisplay as StyleableStageText).x - x) + (width - (textDisplay as StyleableStageText).width); //listener for text changing addEventListener(TextOperationEvent.CHANGE, setHeight); }); } private function setHeight(event:TextOperationEvent):void { //line number is textwidth divided by component width _lineNumber = (((textDisplay as StyleableStageText).measureText(text).width + _lineNumber * _padding) / width) + 1; //text height is line number * text height var newHeight:int = _lineNumber * (textDisplay as StyleableStageText).measureText(text).height; //if new height > min height, set height if (newHeight > _minHeight) height = newHeight; } } } 

Hope this helps.

EDIT: With a lot of lines, the height of the TextArea increases too much. It must be.

0
source share

All Articles