因为textWidth属性在spark textinput中无法访问,我们如何才能获得该属性?
答案 0 :(得分:7)
TextLineMetrics
的东西
你可以这样做
var tm:TextLineMetrics = label.measureText( name );
var width:int = tm.width;
这是一个例子
<?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>
这将为您提供实际宽度