addevent keyboard to external swf not working
I have looked at other questions and online but still cant figure out where I am going wrong I am adding 2 events to a externally loaded swf
One works, and one doesnt?!? the function names are correct so I can see what Im missing
my_loadedSwf = loadEvent.currentTarget.content as MovieClip;
my_loadedSwf.addEventListener(Event.ENTER_FRAME, my_loadedSwf.enterFrameHandler);
my_loadedSwf.addEventListener(KeyboardEvent.KEY_DOWN, my_loadedSwf.myOnPress);
addChild(my_loadedSwf);
the enterFrameHandler is working, but onPress is开发者_如何学JAVAnt?!
Any help would be great
Thanks
EDIT:
I have set my_Loader.tabEnabled = true;
has not changed anything though
MORE EDITS
Sorry, set my_loadedSwf.tabEnabled = true;
and it now works great
EDITS TO THE ABOVE Actually, it isnt working, I have to press 'tab' to take control of the player
ANSWER
Arrrgh, sorry for all the edits I removed the tab index code and added focus to the loaded swf
Keyboard events are usually captured/listened to at stage level. You should add the keyboard listener to the stage, and still target whatever handler you want:
stage.addEventListener(KeyboardEvent.KEY_DOWN, my_loadedSwf.myOnPress);
try this:
//Load Complete Event Handler
private function loadCompleteEventHandler(evt:Event):void
{
//Remove The Event Listener
evt.currentTarget.removeEventListener(Event.COMPLETE, loadCompleteEventHandler);
//Loaded external swf is a display object, so you can add it to the display list
addChild(evt.currentTarget.content);
//To access the loaded external swf's public methods and properties you can cast it as an object
var myExternalSwf:Object = evt.currentTarget.content as Object;
addEventListener(Event.ENTER_FRAME, myExternalSwf.enterFrameHandler);
addEventListener(KeyboardEvent.KEY_DOWN, myExternalSwf.myOnPress);
}
精彩评论