tags:

views:

444

answers:

2

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 on the TextInput field using <mx:SetProperty/>? I've tried the following, but it only results in the field being highlighted -- the cursor does not appear in the TextInput:

<mx:SetProperty target="{stage}" name="focus" value="{myTextInput}"/>

Long story short, I want the cursor to appear in the field.

UPDATE: I figured it out. See comments for solution.

+1  A: 

I try to avoid using the AddChild state tag. It's usually better to put all that in a component, and use SetProperty to set visible and includeInLayout when you want it to display.

You can always override visible in your custom component to set the focus to the field. Or create a custom setter than does the same thing

public function set show(value:Boolean):void
{
  visible = true;
  includeInLayout = true;
  if (value)
  myFunctionThatSetsTheFocus();
}
Sean Clark Hess
A: 

Add a "creationComplete" to the TextInput and had it call a method that setFocus on the TextInput

Huuuze