Skip navigation
Currently Being Moderated

Need to click on flash movie to set focus

Aug 17, 2012 1:47 PM

Using Flash CS4 Pro v. 10.0.2.

 

Any time I make a movie that uses onKeyDown, publish the swf + html files to my webserver, and test the movie from my browser, I have to click the movie once or twice before it gets focus and register my keystrokes.

 

I got a good answer for this a little over a year ago, but unfortunately I have misplaced it.

 

Could someone help me out? 

 

Thanks in advance,

 

Ole

 
Replies
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 17, 2012 1:54 PM   in reply to KING-OLE

    if you're using assign as3, use

     

    stage.focus=whatever

     

    to add focus to whatever.

     
    |
    Mark as:
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 17, 2012 2:41 PM   in reply to KING-OLE

    use:

     

     

     

    package

    {

        import flash.display.MovieClip;

        import flash.events.KeyboardEvent;

        import flash.ui.Keyboard;

        import flash.events.Event;

     

        public class Main extends MovieClip

        {

            public function Main()

            {

    stage.focus=this;

                stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

            }

     

            function onKeyDown(event:KeyboardEvent):void

            {

                if (event.keyCode==Keyboard.RIGHT)

                {

                    player.x += 1;   // move the player to the right

                }

            }

        }

    }

     

     
    |
    Mark as:
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 17, 2012 11:23 PM   in reply to KING-OLE

    you can use javascript in your html to assign focus to your swf when your html loads:

     

    window.document.yourobjecttagname.focus()

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points