3 Replies Latest reply on Jul 31, 2009 9:16 PM by yonghan79

    on application load, textInput focus

    popster

      after endless searching with no resolution, I have a simple application with a textInput control.

       

      I simply want to setFocus on the textInput control without the user doing anything.

       

      I found several posts but I didn't quite understand the solution.

       

      I didn't know where to put this in my html document.  Plus, I didnt know if I had to change the name the FlashObject.  My mxml project is called practice.mxml.  Anyway, I added an onload event in the body tag of the html file calling practice.focus().  This didn't work.

       

      Other posts mentioned the  callLater class which I did not understand.

       

      the setfocus method does not put the cursor inside the textINput control

       

      please help

       

      One solution was a javascript

      script type="text/javascript">
         function focusFlash()
         {
             theFlashObject.focus();
         }
      </script>

       

        • 1. Re: on application load, textInput focus
          ShardulSingh Level 3

          Hi,

          I am here with the solution of your problem.This issue is little tricky.
          To solve this issue you have to work on both side flex as well as java script.
          And most important thing is that you can not check it during the development
          in the flex envirnment.After building your flex application if you will open
          your swf directly.Then you will see it is working fine.Again when you
          will use this swf in any html etc,then you have to write the java script code.
          I am putting here both the codes Flex as well as javascript. Pls let me know if
          any issue.

           

           

          Flex Code

           

           

           

           

           

           

           

           

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application

           

          xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

          >

          <mx:Script>

          <![CDATA[

           

           

          import mx.managers.BrowserManager;

           

           

          import mx.controls.Alert;

           

           

          private function onCreationComplete(): void

          {

               txtInput.setFocus();

          }

          ]]>

           

           

          </mx:Script>

           

           

          <mx:Canvas left="50" right="50" top="50" bottom="50">

           

           

          <mx:TextInput id="txtInput" width="150" height="50"

          creationComplete="onCreationComplete()"

           

          />

           

           

          </mx:Canvas>

          </mx:Application>

           

           

           

           

          Html Page Code

           

           

          <html>
          <head>
          <script language="JavaScript">
          function focusFlash()
             {
                 setFocusDemo.focus();
             }

          </script>
          </head>

          <body  onload="focusFlash()">

             <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
             id="setFocusDemo" width="100%" height="100%"
             codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
             <param name="movie" value="setFocusDemo.swf" />
             <param name="quality" value="high" />
             <param name="bgcolor" value="#869ca7" />
             <param name="allowScriptAccess" value="sameDomain" />
             <embed src="SetFocusDemo.swf" quality="high" bgcolor="#869ca7"
              width="100%" height="100%" name="setFocusDemo" align="middle"
              play="true"
              loop="false"
              quality="high"
              allowScriptAccess="sameDomain"
              type="application/x-shockwave-flash"
              pluginspage="http://www.adobe.com/go/getflashplayer">
             </embed>
          </object>
          </body>

          </html>

           

           

           

           

           

          Hope  this will full fill your requirement.

           

           

          With Regards

          Shardul Singh Bartwal

          1 person found this helpful
          • 2. Re: on application load, textInput focus
            popster Level 1

            Outstanding!!!

             

            Thanks for your help Shardul

             

            There's so much to learn about Actionscript.

            • 3. Re: on application load, textInput focus
              yonghan79

              Hi Popster..I found out another way..Although it says that it doesn't work with safari,opera and chrome.. Here is the link http://carrythezero.net/blog/2009/01/20/flex-textinput-focus-issues/ .. ^_^