我有以下MXML:
<mx:State name="myState">
<mx:AddChild relativeTo="{myhbox}" position="after">
<mx:Box verticalAlign="middle" horizontalAlign="center" width="100%" height="100%">
<mx:Form id="myForm" width="479" verticalScrollPolicy="off" horizontalScrollPolicy="off">
<mx:FormItem label="My Label:" fontWeight="bold" id="myLabel" direction="vertical">
<mx:TextInput id="myTextInput" width="282" />
<mx:HBox>
<mx:Button label="Go" click="go();" id="goButton" />
</mx:HBox>
</mx:FormItem>
</mx:Form>
</mx:Box>
</mx:AddChild>
</mx:State>
如何使用&lt; mx:SetProperty /&gt;?在TextInput字段上设置焦点?我尝试了以下内容,但只会导致字段突出显示 - 光标不会出现在TextInput中:
<mx:SetProperty target="{stage}" name="focus" value="{myTextInput}"/>
长话短说,我希望光标出现在字段中。
更新:我明白了。请参阅解决方案的评论。
答案 0 :(得分:1)
我尽量避免使用AddChild状态标记。通常最好将所有内容放在组件中,并在需要显示时使用SetProperty设置visible和includeInLayout。
您始终可以在自定义组件中覆盖可见,以将焦点设置为字段。或创建自定义setter而不是同样的东西
public function set show(value:Boolean):void
{
visible = true;
includeInLayout = true;
if (value)
myFunctionThatSetsTheFocus();
}
答案 1 :(得分:1)
向TextInput添加“creationComplete”并让它在TextInput上调用setFocus的方法