7 Replies Latest reply on Sep 2, 2009 3:50 AM by sathiyabala

    How to set focus on a textbox

    sathiyabala

      Hai

       

              I need to set focus on the textbox, now i have used the code which i have given below, it is focusing on the textbox but i am not able to tye anything on the textbox only after the user clicks using mouse on the txtbox , after that oly i can type the txt on it.

       

              Without onclick of the txtbox, in onfocus itself i need to type the text in txtbox.

           

              I am using the setfocus in the login page for the username, but not able to type the txt.

       

              Login page is in flex, i used to call the swf directly while build. it is not passed through HTML

       

              can anyone help me.

       

      Thanks In Advance

       

         

      private

       

      function getfocusLogin(event:Event):void{

       

      userName.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyEvent);

      password.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyEvent);

      log.addEventListener (KeyboardEvent.KEY_DOWN , EnterKeyEvent);

      userName.setFocus();

       

       

      }

       

       

       

       

      private function EnterKeyEvent (event:KeyboardEvent):void{

       

       

      if(event.keyCode == 13){

       

      login();

      }

      }

       

       

       

       

       

       

       

      <mx:HTTPService

       

       

      id="logIn" showBusyCursor="true" useProxy="false" url="../LoginAction.do" method="POST" result="loginresultHandler(event)" fault="loginfaultHandler(event)"

      >

       

       

      <mx:request>

       

       

      <userName>{userName.text}

      </userName>

       

       

      <password>{password.text}

      </password>

       

       

      </mx:request>

       

       

      </mx:HTTPService>

        • 1. Re: How to set focus on a textbox
          Flex harUI Adobe Employee

          This is a common issue with Flash in Browsers.  AFAIK there is only a solution for IE, not other browsers and it involves JavaScript call setFocus on the object tag on one of the document or window events.  If you google you'll find it.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: How to set focus on a textbox
            sathiyabala Level 1

            Hai

                    

                        Thank you for your reply, but i am not able to get any from google, any other thing can u suggest

             

             

                        Emergency pl

             

             

             

             

             

             

            Thanks in Advance

            • 3. Re: How to set focus on a textbox
              ShardulSingh Level 3

              Hi,

              Pls find the solution of your problem, I have replied this question for someone else here.Pls let me know if you have any issue still.

               

              http://forums.adobe.com/message/2132197#2132197

               

               

               

              Hope this will fullfill your requirement.

               

               

               

              with Regards,

               

              Shardul Singh Bartwal

              • 4. Re: How to set focus on a textbox
                sathiyabala Level 1

                Hai Shardul Singh Bartwal

                 

                 

                               Thank u For your reply , but i am not using html, directly the swf oly i am using.

                 

                               In build.xml i will mention where the swf should be placed after build, so it will be placed in that path, for login how to send swf from html

                 

                 

                              Can u help me

                 

                Thanks In Advance

                • 5. Re: How to set focus on a textbox
                  ShardulSingh Level 3

                  Hi,

                  Sorry to say I am not getting your problem.

                  But what I will suggest dont do any thing else,simply open the swf which you have been created after building your application i.e. under the

                  'bin-debug' or 'bin-release' folder.I think in that it will be already working fine but in builder during running or debugging you will not see it working.

                   

                   

                   

                  Shardul Singh Bartwal

                  • 6. Re: How to set focus on a textbox
                    sathiyabala Level 1

                    Hai  Shardul Singh Bartwal

                     

                     

                                    I implemented as u said, the cursor is blinking over that textbox and the focus is also there, but not able to type anyting

                                               in that textbox....

                     

                     

                     

                    FLEX CODE

                     

                     

                    private function getfocusLogin(event:Event):void{

                     

                    userName.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyEvent);

                    password.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyEvent);

                    log.addEventListener (KeyboardEvent.KEY_DOWN , EnterKeyEvent);

                    userName.setFocus();

                    }

                     

                     

                     

                    mx:FormItem

                     

                     

                    label="UserName" color="#F29E0C" themeColor="#EB8A0B" fontFamily="Verdana"

                    >

                     

                     

                    <mx:TextInput id="userName" x="717" y="273" width="140" color="#050505" name="user" creationComplete="getfocusLogin(event)"

                    />

                     

                     

                    </mx:FormItem>

                     

                     

                     

                     

                    HTML CODE

                     

                    <

                     

                    html>

                    <

                     

                    head>

                    <

                     

                    title>GRC Project</title>

                     

                    <link rel="shortcut icon" href="<%=request.getContextPath()%>/imgs/login/favicon.ico" >

                     

                    <script>

                     

                    function

                     

                    focusFlash(){

                     

                     

                    setFocus.focus();

                    lapFocus.focus();

                    }

                     

                    functi

                     

                    on fetchresolution(){

                     

                     

                    if ((screen.width < 800 ) && (screen.height < 600)){

                    ale

                    rt("Lowest height "+ screen.width);

                    ale

                    rt("Lowest width"+ screen.height);

                    }else

                     

                    if ((screen.width <= 1024) && (screen.height <= 768)){

                    obj = document.getElementBy

                    Id("desktop");

                    obj.style.visibility

                    = 'visible';

                    }else

                     

                    if ((screen.width <= 1280 ) && (screen.height <= 800)){

                    obj = document.getElementBy

                    Id("laptop");

                    obj.style.visibility

                    = 'visible';

                    }

                    }

                     

                     

                    </script>

                    </

                     

                    head>

                    <

                     

                    body bgcolor="#FFFFFF" body scroll="no" marginheight=0 topmargin=0 leftmargin=0 bottommargin=0 rightmargin=0 onLoad="fetchresolution()">

                    <

                     

                    div id="desktop" style="position: absolute; visibility: hidden;">

                    <

                     

                    OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="setFocus" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

                    height

                     

                    ="600" width="1020" id="Charting">

                     

                    <param name=movie value="<%=request.getContextPath()%>/pages/flexreportlogin/flexreportlogin.swf">

                     

                    <param name="quality" value="best" />

                     

                    <param name="scale" value="noscale" />

                     

                    <param name="salign" value="t" />

                     

                    <param name="wmode" value="opaque" />

                     

                    <param name="allowScriptAccess" value="sameDomain" />

                     

                    <EMBED src="<%=request.getContextPath()%>/pages/flexreportlogin/flexreportlogin.swf" allowScriptAccess="sameDomain" quality=high NAME="Charting" ALIGN="" TYPE="application/x-shockwave-flash" height="600" width="1020"

                     

                     

                    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

                     

                    </EMBED>

                    </

                     

                    OBJECT>

                    </

                     

                    div>

                     

                    <

                     

                    div id="laptop" style="position: absolute; visibility: hidden;">

                    <

                     

                    OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="lapFocus" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

                    width

                     

                    ="1275" HEIGHT="650" id="lapchart">

                     

                    <param name=movie value="<%=request.getContextPath()%>/pages/flexreportlogin/flexreportlogin.swf">

                     

                    <param name="quality" value="best" />

                     

                    <param name="scale" value="noscale" />

                     

                    <param name="salign" value="t" />

                     

                    <param name="wmode" value="opaque" />

                     

                    <param name="allowScriptAccess" value="sameDomain" />

                     

                    <EMBED src="<%=request.getContextPath()%>/pages/flexreportlogin/flexreportlogin.swf" allowScriptAccess="sameDomain" quality=high NAME="lapchart" ALIGN="" TYPE="application/x-shockwave-flash" width="1275" HEIGHT="650"

                     

                     

                    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

                     

                    </EMBED>

                    </

                     

                    OBJECT>

                    </

                     

                    div>

                     

                    </

                     

                    body>

                    </

                     

                    html>

                     

                     

                     

                     

                     

                                   

                    • 7. Hai Shardul Singh Bartwal that is working fine Thank u
                      sathiyabala Level 1

                      Hai Shardul Singh Bartwal

                       

                       

                                     Thank u For your reply , It is working fine, it is correct answer, thank u very much....