5 Replies Latest reply on Mar 9, 2009 7:45 AM by Richard_Abbott

    Trying to set focus to a field

    bitwyse Level 1
      I know I have done this before but I can't seem to get it to work. Here is a stripped down example. Any ideas why the set focus doesn't work? The user name field is highlighted as if it has the focus but when I type the browser thinks it's somewhere else. . .

        • 1. Re: Trying to set focus to a field
          bitwyse Level 1
          Found the answer to this one. Woo Hooo you can read the details where I found them
          http://carrythezero.net/blog/2009/01/20/flex-textinput-focus-issues/

          The abbreviated version is this:
          private function onInit() : void
          {
          ExternalInterface.call('function browserFocus(){document.getElementById(\'testLogin\').focus();}');
          tiUserName.setFocus();
          }

          Note testLogin is the name of my main mxml file.
          • 2. Re: Trying to set focus to a field
            Richard_Abbott Level 3
            bitwyse,
            I had a look at a similar issue recently and found that there were browser dependcies in the JavaScript call. The Adobe documentation goes into this a bit but I could only reliably get it working for IE and Firefox, not Safari, Opera, Google Chrome etc. If you have found a generic way I'd be very happy to see it and will check out the link you gave,
            Richard
            • 3. Re: Trying to set focus to a field
              Richard_Abbott Level 3
              Hi again bitwyse,
              yes, I just had another check through this and it definitely does not work across all browsers. Whether this matters or not depends on your situation, of course! A few weeks ago I fiddled a lot with different permutations and decided that there were differences not only in how the application array is address between browsers, but also in how rapidly and in what order different browsers instantiate the application. I tried putting delays into either the Flex bit or the JavaScript bit without astonishing success and in the end shelved it since it was taking too much time.
              Sometime I hope to get back to a genuine cross-browser solution but have not yet found it,
              Richard
              • 4. Re: Trying to set focus to a field
                bitwyse Level 1
                Hey Rich,
                I only tested this in IE and Firefox. They are my main concerns at the moment. I will need to test on Safari shortly but I am confident this will work.

                Let me know what you find . . .
                • 5. Re: Trying to set focus to a field
                  Richard_Abbott Level 3
                  Hi bitwyse,
                  no joy yet outside IE and FF. I did find enough moans and winges round the internet that persuaded me that it is a real problem and one not readily resolvable in Flex, eg the following from
                  http://stackoverflow.com/questions/594821/object-focus-problem-with-safari-and-chrome-brow sers
                  ----------
                  Unfortunately there is no way to ensure that you can set focus to a flash file that works in all browsers. IE and Firefox have solved this problem (for the most part), but Chrome and Safari are both based off of Webkit which does not have a solution.
                  ---------
                  Sounds like we're just out of luck for now... but like you, IE and FF are my main concerns, I just wanted to find some generic solution.
                  Richard