Fredrik
Fredrik

Reputation: 61

AIR application, set cursor position in form

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?

Upvotes: 2

Views: 2683

Answers (4)

SergeyT
SergeyT

Reputation: 11

I can advise to set active a native window before set focus on text input. Something like this:

private function creationCompleteHandler(event:FlexEvent):void {
    stage.nativeWindow.activate();
    loginName.setFocus();
    loginName.selectAll();
}

Upvotes: 1

yonos
yonos

Reputation: 16

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>

Upvotes: 0

grapefrukt
grapefrukt

Reputation: 27045

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);

Upvotes: 3

Dennis
Dennis

Reputation: 3488

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

Upvotes: 1

Related Questions