Cross Broswer Q - How to force flash to have focus...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paulcybulski
    New Member
    • Nov 2007
    • 25

    Cross Broswer Q - How to force flash to have focus...

    I want to have the flash document have focus when the page initially loads...so the user can use the mouse scroll wheel to zoom in and out on the map that is on stage...(withou t having to click inside the browser window first)...

    Now, I have already gotten this to work with IE by using the following code...

    [HTML]<body onLoad="window. document.eXfX.f ocus();">[/HTML]

    But like I said, this only works in IE, and I cannot find any information on forcing focus in other browsers...and I do not know how I would decide which browser is being used...I'm fairly new to JS so bare with me...
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you show the HTML code that displays the Flash content?

    Comment

    • paulcybulski
      New Member
      • Nov 2007
      • 25

      #3
      [html]
      <body onLoad="window. document.eXfX.f ocus();">
      <script type="text/javascript" src="swfobject. js"></script>
      <div id="flashconten t">
      <a href="http://www.macromedia. com/go/getflashplayer" target="_blank" >Click here to download Macromedia Flash Player to view the content of the page! Once the install is complete click Refresh to view this page.</a>
      </div>
      <script type="text/javascript">
      var so = new SWFObject("blah .swf", "eXfX", "100%", "100%", "8", "#ffffff");
      so.write("flash content");
      </script>
      </body>
      [/html]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        "eXfX" (the second parameter to SWFObject) is the ID, not the name of the object/embed element, so you want to use document.getEle mentById("eXfX" ).focus().

        Comment

        • paulcybulski
          New Member
          • Nov 2007
          • 25

          #5
          Originally posted by acoder
          "eXfX" (the second parameter to SWFObject) is the ID, not the name of the object/embed element, so you want to use document.getEle mentById("eXfX" ).focus().
          that code only works in IE...unfortunat ely FF doesn't treat it the same way and you still have to click the swf to give it focus...

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            From this technote it appears that this only works in IE, so you'll have to use the first solution.

            Comment

            • paulcybulski
              New Member
              • Nov 2007
              • 25

              #7
              Originally posted by acoder
              From this technote it appears that this only works in IE, so you'll have to use the first solution.
              so there is no way to do this in FF? Nothing that I have tried has worked!!!

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Well, there is a way, but it's probably not what you're looking for.

                Originally posted by from TechNote
                There are two ways to give focus to the Flash movie.

                * Have the user click in the Flash movie Add a button to the first frame of the movie that the user must click in order to continue (an "Enter", "Start" or "Login" button, for example). Any subsequent key presses can be detected by Flash.
                * Use JavaScript to give focus to Flash The JavaScript focus() method can automatically give focus to the Flash movie when the HTML page containing it loads.

                Note: This method only works on Windows versions of Internet Explorer.
                If you see the note, using JavaScript to give focus to Flash only works in IE. For other browsers, use the first solution.

                Comment

                Working...