13 Replies Latest reply on Aug 4, 2009 6:36 PM by ^^GOUST^^

    Receiving the text input cursor

    ^^GOUST^^ Level 1

      Staff when I load my application, I have a field textinput which I want that it receives focus and the cursor |, for write?

       

       

      using id_text.setSelection(0,0);

       

      fail

        • 1. Re: Receiving the text input cursor
          Michael Borbor Level 4

          That's a browsers/security restriction you can overtake that using

          javascript. But for that you need to implement different js code for a

          browser or another.

          • 2. Re: Receiving the text input cursor
            ^^GOUST^^ Level 1

            I only want that the cursor appears in textinput when loading the page

            • 4. Re: Receiving the text input cursor
              Gregory Lafrance Level 6

              Actually, to set the focus when the page loads, you need to do a bit more.

               

              If this post answers your question (and I believe it does, it just worked for me ) or helps, please mark it as such.

               

              1) In the HTML wrapper file template index.template.html add this text directly after the opening <body> tag:

               

               

              <script type="text/javascript">

              function setBrowserFocus(){

              document.getElementById('${application}').focus();

              }

              </script>

              **************************************************************

              2) In the application, add this code (full code further below):

              creationComplete="onLoad(event)"

               

              import flash.external.ExternalInterface;

              private function onLoad(event:Event):void { 
                  ExternalInterface.call('setBrowserFocus'); 
                  this.txt.setFocus(); 
              }

               

              where "txt" is the ID of the TextInput or other Flex control you want to get the focus on app load.

              ***************************************************************

              3) In the Flex Builder menubar:

              Project - Properties - Flex Compiler - Additional compiler arguments

               

              -use-network=true

               

              You've got to test this by posting the code to the server, it may not work locally, unless you adjust your Flash Player settings.

               

              --------------- TestApps.mxml --------------

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                creationComplete="onLoad(event)">
                <mx:Script>
                  <![CDATA[
                    import flash.external.ExternalInterface;

                    private function onLoad(event:Event):void { 
                      ExternalInterface.call('setBrowserFocus'); 
                      this.txt.setFocus(); 
                    }     
                  ]]>
                </mx:Script>
                <mx:TextInput id="txt"/>
              </mx:Application>

               

              --------------- entire wrapper HTML template - index.template.html ---------------

              <!-- saved from url=(0014)about:internet -->

              <html lang="en">

               

              <!--

              Smart developers always View Source.

               

              This application was built using Adobe Flex, an open source framework

              for building rich Internet applications that get delivered via the

              Flash Player or to desktops via Adobe AIR.

               

              Learn more about Flex at http://flex.org

              // -->

               

              <head>

              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

               

              <!-- BEGIN Browser History required section -->

              <link rel="stylesheet" type="text/css" href="history/history.css" />

              <!-- END Browser History required section -->

               

              <title>${title}</title>

              <script src="AC_OETags.js" language="javascript"></script>

               

              <!-- BEGIN Browser History required section -->

              <script src="history/history.js" language="javascript"></script>

              <!-- END Browser History required section -->

               

              <style>

              body { margin: 0px; overflow:hidden }

              </style>

              <script language="JavaScript" type="text/javascript">

              <!--

              // -----------------------------------------------------------------------------

              // Globals

              // Major version of Flash required

              var requiredMajorVersion = ${version_major};

              // Minor version of Flash required

              var requiredMinorVersion = ${version_minor};

              // Minor version of Flash required

              var requiredRevision = ${version_revision};

              // -----------------------------------------------------------------------------

              // -->

              </script>

              </head>

               

              <body scroll="no">

              <script type="text/javascript">

              function setBrowserFocus(){

              document.getElementById('${application}').focus();

              }

              </script>

              <script language="JavaScript" type="text/javascript">

              <!--

              // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)

              var hasProductInstall = DetectFlashVer(6, 0, 65);

               

              // Version check based upon the values defined in globals

              var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

               

              if ( hasProductInstall && !hasRequestedVersion ) {

              // DO NOT MODIFY THE FOLLOWING FOUR LINES

              // Location visited after installation is complete if installation is required

              var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";

              var MMredirectURL = window.location;

              document.title = document.title.slice(0, 47) + " - Flash Player Installation";

              var MMdoctitle = document.title;

               

              AC_FL_RunContent(

              "src", "playerProductInstall",

              "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"" ,

              "width", "${width}",

              "height", "${height}",

              "align", "middle",

              "id", "${application}",

              "quality", "high",

              "bgcolor", "${bgcolor}",

              "name", "${application}",

              "allowScriptAccess","sameDomain",

              "type", "application/x-shockwave-flash",

              "pluginspage", "http://www.adobe.com/go/getflashplayer"

              );

              } else if (hasRequestedVersion) {

              // if we've detected an acceptable version

              // embed the Flash Content SWF when all tests are passed

              AC_FL_RunContent(

              "src", "${swf}",

              "width", "${width}",

              "height", "${height}",

              "align", "middle",

              "id", "${application}",

              "quality", "high",

              "bgcolor", "${bgcolor}",

              "name", "${application}",

              "allowScriptAccess","sameDomain",

              "type", "application/x-shockwave-flash",

              "pluginspage", "http://www.adobe.com/go/getflashplayer"

              );

              } else { // flash is too old or we can't detect the plugin

              var alternateContent = 'Alternate HTML content should be placed here. '

              + 'This content requires the Adobe Flash Player. '

              + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';

              document.write(alternateContent); // insert non-flash content

              }

              // -->

              </script>

              <noscript>

              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

              id="${application}" width="${width}" height="${height}"

              codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">

              <param name="movie" value="${swf}.swf" />

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

              <param name="bgcolor" value="${bgcolor}" />

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

              <embed src="${swf}.swf" quality="high" bgcolor="${bgcolor}"

              width="${width}" height="${height}" name="${application}" align="middle"

              play="true"

              loop="false"

              quality="high"

              allowScriptAccess="sameDomain"

              type="application/x-shockwave-flash"

              pluginspage="http://www.adobe.com/go/getflashplayer">

              </embed>

              </object>

              </noscript>

              </body>

              </html>

               

               

               

               

              • 5. Re: Receiving the text input cursor
                ^^GOUST^^ Level 1

                   
                helped, but not the cursor blinks in the  textinput, add me on msn goust_avo@hotmail.com I will send you the sources

                • 6. Re: Receiving the text input cursor
                  Gregory Lafrance Level 6

                  If you run the sample code I provided, does that work for you?

                  • 7. Re: Receiving the text input cursor
                    ^^GOUST^^ Level 1
                    is not a flex project is a dynamic web project in eclipse, add on msn
                    • 8. Re: Receiving the text input cursor
                      Gregory Lafrance Level 6

                      Hmmm... This is a Flex forum. Not sure I'll be able to be of much help on this one. Sorry...

                      • 9. Re: Receiving the text input cursor
                        ^^GOUST^^ Level 1
                        I do not know what 's wrong with giving but the idea is the same
                        • 10. Re: Receiving the text input cursor
                          Gregory Lafrance Level 6

                          I think for me my primary expertise is in Flex, and though I have some expertise in other web technologies, others might be able to more quickly look at your code and help you out.

                          • 11. Re: Receiving the text input cursor
                            ^^GOUST^^ Level 1

                            flex project is perfect, but in dynamic web project, when you put the html code there, it disappears

                             

                            <script type="text/javascript">

                             

                            setBrowserFocus function () (

                             

                            document.getElementById ( '$ (application)'). focus ();

                             

                            )
                            • 12. Re: Receiving the text input cursor
                              ^^GOUST^^ Level 1
                              I think it worked but I had to put the code after the one for you
                              ExternalInterface.call ( 'setBrowserFocus');
                              This.txt.setFocus ();
                              Alert.show ("");

                               

                              I'm trying to figure out how to solve now, putting a break
                              • 13. Re: Receiving the text input cursor
                                ^^GOUST^^ Level 1

                                resolved

                                 

                                need not handle html
                                the script's own mxml

                                 

                                import flash.external.ExternalInterface;

                                 

                                         ExternalInterface.call ( "document.getElementById ( 'name of the application'). Focus ()");
                                     Txt_id.setFocus ()