-
SWF loaded into container keyboard events not working
I am loading game levels swf's into a container swf.
The game level swf doesn't register the keyboard events. The EnterFrame and MouseEvents work with the preface "this.addEventListener(MouseEvnet.CLICK, doSomething)", but not the KeyBoard Events.
Container code:
PHP Code:
var levelOneMC:MovieClip
var myloader:Loader= new Loader();
myloader.load(new URLRequest("levelOne.swf"));
myloader.contentLoaderInfo.addEventListener(Event.INIT, loadLevelOne);
function loadLevelOne(evt:Event){
levelOneMC = myloader.content as MovieClip;
addChild(levelOneMC);
}
levelOne code:
PHP Code:
//Works with just levelOne, doesn’t work in container
//this.stage.addEventListener(KeyboardEvent.KEY_DOWN,test);
//Works with just levelOne, doesn’t work in container
//stage.addEventListener(KeyboardEvent.KEY_DOWN,test);
//doesn’t work in either levelOne or in container
//this.addEventListener(KeyboardEvent.KEY_DOWN,test);
function test(e:KeyboardEvent){
trace("this is working");
}
Can any one help?
-
.
Hi,
Try
PHP Code:
var levelOneMC:MovieClip; var myloader:Loader= new Loader(); myloader.load(new URLRequest("levelOne.swf"));
myloader.contentLoaderInfo.addEventListener(Event.INIT, loadLevelOne); function loadLevelOne(evt:Event) { levelOneMC = myloader.content as MovieClip; addChild(levelOneMC); stage.addEventListener(KeyboardEvent.KEY_DOWN,levelOneMC.test); }
-
Ta DA! Works. I had moment of panic when it didn't work the first time, but it was the stage focus.
I take it keyboard events will not work in a loaded SWF. Eh, whatever works.
Thanks fruitbeard.
-
.
HI,
You might be better doing it this way if you want it to initaiate either inside of the container or outside of container.
Container code:
PHP Code:
var levelOneMC:MovieClip;
var myloader:Loader= new Loader();
myloader.load(new URLRequest("levelOne.swf"));
myloader.contentLoaderInfo.addEventListener(Event.INIT, loadLevelOne);
function loadLevelOne(evt:Event)
{
levelOneMC = myloader.content as MovieClip;
addChild(levelOneMC);
}
levelOne code:
PHP Code:
if (stage)
{
initiate();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, initiate);
}
function initiate(e:Event = null):void
{
trace("Now loaded and ready for stage.");
removeEventListener(Event.ADDED_TO_STAGE,initiate);
stage.addEventListener(KeyboardEvent.KEY_DOWN,test);
}
function test(e:KeyboardEvent):void
{
trace("this is working");
}
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|