开发者

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

开发者 https://www.devze.com 2023-01-31 09:17 出处:网络
as textWidth property is no more accessible in spark textinput how we can get that 开发者_StackOverflow社区property ?in spark there\'s something called TextLineMetrics

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

精彩评论

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

关注公众号