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
Thanks, but not sure I follow you.
Here's a simple example in a single AS file:
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.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
function onKeyDown(event:KeyboardEvent):void
{
if (event.keyCode==Keyboard.RIGHT)
{
player.x += 1; // move the player to the right
}
}
}
}
When I press the RIGHT arrow key, the player object in my FLA file moves to the right.
When I publish this to a webserver, running the SWF file from an HTML file, I have to click the movie with the mouse before I can move the player with the keyboard.
Thanks,
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
}
}
}
}
North America
Europe, Middle East and Africa
Asia Pacific