How can I set focus property on TextInput created with AddChild?
I have the following 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>
How do I set focus to a TextInput field using <mx: SetProperty />? I've tried the following, but it only results in the highlighted field - no cursor appears in the TextInput:
<mx:SetProperty target="{stage}" name="focus" value="{myTextInput}"/>
In short, I want the cursor to appear in the field.
UPDATE . I understood that. See the comments for the solution.
0
a source to share
2 answers
I am trying to avoid using the AddChild status tag. It's usually best to put all of this in a component and use SetProperty to set visible and includeInLayout when you want to display it.
You can always override the visibility in your custom component to set focus to the field. Or create a custom setter than the same.
public function set show(value:Boolean):void
{
visible = true;
includeInLayout = true;
if (value)
myFunctionThatSetsTheFocus();
}
+1
a source to share