开发者

how can we get the actual text width in pixel of Spark TextInput?

as textWidth property is no more accessible in spark textinput how we can get that 开发者_StackOverflow社区property ?


in spark there's something called TextLineMetrics

you can do it like this

var tm:TextLineMetrics = label.measureText( name );
var width:int = tm.width;

here's an example

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.controls.Text;

        protected function cmdDoAction_clickHandler(event:MouseEvent):void
        {
            var tm:TextLineMetrics = cmdDoAction.measureText(cmdDoAction.label);
            var _width:int = tm.width;

            Alert.show(_width.toString());
        }
    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:Button id="cmdDoAction"
          label="Kensodev"
          click="cmdDoAction_clickHandler(event)"/>
    </s:Application>

This will give you the actual width

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜