Posts tonen met het label dd_winterspel. Alle posts tonen
Posts tonen met het label dd_winterspel. Alle posts tonen

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..

CS5 project window..

not only was I programming in as2, I was using CS3. Well, no more..
We have bought the total complete master version of CS5..
So I have now installed it, to be totally up to date, but what's this:
THEY HAVE STOLEN MY PROJECT WINDOW, that I loved in CS3 professional.
I was making a *.flp for every project I did.
Especially in as3, using all these classes, it allowed me to create a logical structure and keep things togeter, like this:

I want my project window back the way is was. Now it just copies my hard disk.. We have a little thing called Explorer, that does that (and better)..
I cannot even open my old *.flp's, never heard of backward-compatibility, or did you think: well we didn't giv'm any backward compatibility on as3-as2, and nobody protested, so why not bugger all?

I cannot think why anyone would consider this an improvement. Anyone....?

1046: Type was not found or was not a compile-time constant: Loader.

As3 has been driving me crazy.
I tried creating a container the way I used to do this in as2.
Load in stuff with LoadMovieNum (Yes, I'm old fashioned, but I found the "layer"-concept very usefull in building minisites).

The pre is that you can develop a page (almost) completely independant and then get stuff from _level0.. The beauty is, because there is a _root as well as a _level0 the _root functionality isn't lost.
But oh well, as2 is long ago.

When I was trying to create this in as3, I got this enigmatic error when I just followed the example from adobe:

package nl.ludatic.container{
 import flash.display.*;
 import flash.events.*;
 import flash.net.URLRequest;
 import flash.net.navigateToURL;
 import flash.system.*;
 import flash.text.*;

 public class Container extends MovieClip
 {
  private var loader:Loader=new Loader();

and BAM!
There was no way I could get the compiler to go past this line...

Now what happened:
nl.ludatic.container means, the compiler has to look in nl/ludatic/container to get to the Container class..
In this directory I had also put a empty file called Loader.as.
Apparantly the compiler looked at this file when I said new Loader() and found it empty, so it concluded there was NO Loader class.

Now I don't know how an empty file can override a hard import, but it did.
I got rid of the file and everything works beautifully.

So I worked it out in the end, but wow...
Oh well, on to the next inexplicable error!

zaterdag 1 januari 2011

as2 to as3

I'm a regular flash-guru according to some. I program games, so if there is a problem in Flash, I usually find it. Up until last year I still programmed in as2 and hadn't done much OOP (Object Oriented Programming)
So I figure, I go learn it in 2011, blog about what I find and maybe make some people happy, who knows.

Now I found out one of the first surprising things quite quickly. Don't think you know something, even when it doesn't seem to have changed.

this is (very concise) as2:
mc.localToGlobal(p={x:0,y:0});

after this p.x and p.y hold the coordinates of mc's anchorpoint on the stage..
I use this a lot in game-development in as2.
I was thrilled that the function hadn't changed..
BUT!
in as3 the above always leaves you with the original point, nothing happens!
in as3 the snippet would be:
var p:Point=new Point(0,0);
p=mc.localToGlobal(p);

As you can see, the difference is subtle. In as2, the point that you give is modified. In as3 the point is returned from the function and the original point is left unaltered.
I know the latter is more correct and I understand now why they did it..
But WHY weren't we warned. I found NO reference to this whatsoever.

Bad Adobe!