开发者

how to place cursor in textinput in Flex3

开发者 https://www.devze.com 2023-02-27 09:55 出处:网络
how to place cursor in a text input when user login form comes. I want cursor place in username text input. .Any help is g开发者_如何学JAVAreatly appreciated! To go along with J_A_X\'s answer, if you\

how to place cursor in a text input when user login form comes. I want cursor place in username text input. .Any help is g开发者_如何学JAVAreatly appreciated!


To go along with J_A_X's answer, if you're trying to set focus on a component when the application first loads, you'll also need to use some javascript to set the focus on your SWF.

Here's the sample code from that article:

The Javascript:

<script type="text/javascript">
function onFlexInitialized()
{
    //alert("onFlexInitialized");

    <!-- Force the browser to set flex app with focus -->
    document.getElementById("${application}").focus();
}
</script>

The ActionScript:

/**
 * Constructor.
 */
public function AppController()
{
    FlexGlobals.topLevelApplication.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 4
        //Application.application.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3
}

/**
 * Handles the application complete event.
 */
protected function onAppComplete(e:FlexEvent):void
{
    FlexGlobals.topLevelApplication.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 4
        //Application.application.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3

    if(ExternalInterface.available)
    {
        ExternalInterface.call("onFlexInitialized");
    }
}


You can't manually move the mouse cursor, however, you can always set the focus on the TextInput after your form is complete:

<mx:Canvas creationComplete="onCreationComplete()">
   <mx:Script>
      <![CDATA[
         private function onCreationComplete():void
         {
            input.setFocus();
         }
      ]]>
   </mx:Script>
   <mx:TextInput id="input" />
</mx:Canvas>


    <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Label id="laa" x="264" y="118" width="160"/>
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            [Bindable]
            private var tempArr:Array;
            private function myFunc(event:TextEvent):void{
            tempArr=new Array();

                for(var i:int=0, j:int=0;i<myarr.length;i++){
                if(myarr[i].names.toString().match(textinput.text)){
                        tempArr[j]=myarr[i];
                        j++;
                }else{

                }
                }
                ls.dataProvider=tempArr;
                ls.visible=true;

            }
        ]]>
    </mx:Script>


    <mx:Array id="myarr">
        <mx:Object names="Subudhi"/>
        <mx:Object names="Subbu"/>
        <mx:Object names="Harish"/>
        <mx:Object names="Hari"/>
        <mx:Object names="Subramanyam"/>
        <mx:Object names="Suresh"/>
        <mx:Object names="Surya"/>
        <mx:Object names="Harsha"/>
        <mx:Object names="Geetha"/>
        <mx:Object names="Gentle"/>
        <mx:Object names="gentleman"/>
        <mx:Object names="sunny"/>
        <mx:Object names="sunday"/>
    </mx:Array>
    <mx:TextInput id="textinput" x="264" y="10" textInput="myFunc(event)" focusOut="ls.visible=false"/>
    <mx:List  id="ls" x="264" y="31" height="66"   visible="false" labelField="names" width="160" backgroundColor="#F3EBEB"></mx:List>
</mx:Application>

    enter code here


navigateToURL(new URLRequest("javascript: document.getElementById('XXX').focus();"), "_self"); 
userNameInput.setFocus(); 

Where XXX is the name of the swf file.


ON Adobe forum, solution is provider for almost same issue please ck

How to move the cursor in a text input programatically

Hopes that helps

0

精彩评论

暂无评论...
验证码 换一张
取 消