views:

1295

answers:

3

I have an AIR application with a login form. What I want to do is set the cursor in the first textinput box. I only manage to set the focus on the box, but not the cursor.

Does anyone have an idea for how I can do this?

+1  A: 

From what i know there is no way to control the mouse in actionscript (flash), the mouseX / mouseY property is read-only.

However you could create a "fake mouse" that you can move around in the AIR application but I doubt thats something you want to do, example: http://www.senocular.com/demo/VirtualMouse/VirtualMouse.html

Dennis
+2  A: 

To move the text cursor to a TextField you simply set the stage's focus property to that field.

stage.focus = myTextField;

To move the cursor to a specific index within that TextField, use setSelection():

myTextField.setSelection(54, 70);
grapefrukt
A: 

You need to wait for the flex container to be registered with the display list so you access the stage.

Put a call to init from you creationComplete handler:

<mx:Script>
    <![CDATA[
        import flash.events.Event;

        private function init():void 
        {
            addEventListener(Event.ADDED_TO_STAGE, initScreen, false);

        }

        private function initScreen(e:Event):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, initScreen);
            stage.focus = userName;
        }

    ]]>
</mx:Script>

<mx:Form defaultButton="{enterBtn}">

    <mx:FormHeading label="Form" />
    <mx:FormItem label="Username" tabIndex="1">
        <mx:TextInput id="userName" text="" selectionBeginIndex="0" />
    </mx:FormItem>
    <mx:FormItem label="Password" tabIndex="2">
        <mx:TextInput displayAsPassword="true" id="password"/>
    </mx:FormItem>

</mx:Form>
yonos
Thank you, worked perfectly.
Freedo