woensdag 5 januari 2011

Weird loss of keyboard focus in game..

Ok, I have this game set up in AS3, yeah! But it needs to be loaded in a container (we always develop that way, so the different programmers/designers and backenders don't get in each others way)..

I have a container.swf, loading the splash screen (splash.swf), on the splash screen is a button.
If the button is pressed, the container receives a callback (no, not an event) and clears up the first load, then loads the game on the same movieClip.
This works.
Now I have the same thing for the game, and it works aswell. BUT....
I loose keyboard focus, apparantly to the browser??.. Doesn't a child inherit keyboard focus from the stage???

You can look at my setup here:

http://www.snoep.at/flashcandy/05_01_2010/index.php
Click either start or continue, it doesn't make a difference at this point.
You can play the game, but after you press the start button and the game loads, you have to click again, in order for the keyListeners to do anything.. (Arrow keys and space control Huey Dewey or Louie, it's not decided yet)

There is the ugly solution offcourse: add a popup of sorts, that people have to click, but YUK, it must be doable some other way..
Here is the code:
loader=new Loader();
   loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
   loader.contentLoaderInfo.addEventListener(Event.COMPLETE, pageLoaded);
   loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS, showProgress);
   loader.contentLoaderInfo.addEventListener(Event.INIT, pageInitiated);
   timestamp=getTimer();
   loader.load(new URLRequest(url), new LoaderContext(true));
and of course the handler:
private function pageLoaded(e:Event):void 
  {
   //trace("pageLoaded");
   pageContent=MovieClip(loader.content); // keep for future reference..
   pageLayer.addChild(pageContent); // add is to my Layer, which is a bit like as2 LoadMovieNum :)
   pageContent.setUmbellical(stage,pageCallback); // give the page a reference, to set up the keyListeners..
  }


Can't imagine now, why it wouldn't work.. I hope I find it tomorrow, or I'll just have to go for the ugly solution for now..
I have this great book about as3 and OOp (ActionScript 3.0 Design Patterns) it really helped up to now, who knows, maybe there is something in there that might explain all this..

Geen opmerkingen:

Een reactie posten