Kongregate API Help
Monkey Targets Forums/Flash/Kongregate API Help
| ||
Hi everyone! So I've recently finished my first game, and I'd like to incorporate the Kongregate API. I'm completely new to actionscript, so I followed this tutorial: http://www.monkeycoder.co.nz/Community/posts.php?topic=1825 When I get to step 3, and try to import the Kongregate front-end into my game code, I get the following error(s): MonkeyGame.as(1504):col: 35 Error: Access of undefined property game. var paramObj:Object = LoaderInfo(game.root.loaderInfo).parameters; MonkeyGame.as(1510):col: 2 Error: Access of undefined property Security. Security.allowDomain(apiPath); MonkeyGame.as(1517):col: 2 Error: Access of undefined property game. game.addChild(loader); I haven't a clue what I should do to resolve this. Would anyone be able to offer a little help, please? |
| ||
Okay, it turns out that these errors can be resolved by substituting 'game' for 'this', which I guess is probably the result of changes to Monkey since the tutorial was written, but it still doesn't seem to want to work for me even after this change. Perhaps a more general post is in order... |
| ||
Hello, I received your e-mail about this (since it is also my tutorial). I have not been using Monkey for a while so it is possible that my code got outdated somehow! :) I will look into it and let you know what I find. |
| ||
Thanks Foppy, I'd really appreciate it! :) |
| ||
I am sorry, I can't seem to find out what is going on here right away... In the old version of "Monkey for Flash" (many months ago) there used to be a variable called "game" which was accessible to the AS code that was added later (in this case, by me). So I could tell "game" to connect to Kongregate. Now in the new version (I just installed v69) this variable is gone. I see that you changed it to use "this" instead, but I have trouble understanding why that would work. I can't find where an instance of the game class (MonkeyGame? BBMonkeyGame?) is created that would then be accessible to my own code. I also tried using "this" and indeed it does make the error messages go away. (But I don't understand why.) However, my Monkey Pixels game, compiling correctly to the HTML5 target, now just results in a blue screen for the Flash target (not the Windows kind of blue screen of death, but rather an SWF that just shows a blue rectangle). So now I am unsure if this blue screen swf problem is related to the Kongregate problem, or just some other fault in my own game. Edit: If I comment out all code in function kongregateInit() in kongregate.as, the game shows up correctly. So it is some problem with the kongregate functionality. I suspect the use of "this" to refer to the flash game is not correct, but I am not certain. |
| ||
I have reintroduced the variable "game" in file MonkeyGame.as in mygame.build\flash:package{ import flash.display.*; import flash.events.*; [SWF(width="640",height="480")] public class MonkeyGame extends Sprite{ public function MonkeyGame(){ addEventListener( Event.ADDED_TO_STAGE,OnAddedToStage ); } private function OnAddedToStage( e:Event ):void{ // ================ // ADDED THIS LINE: // ================ game = this; BBMonkeyGame.Main( this ); } } } // ================ // ADDED THIS LINE: // ================ var game:MonkeyGame; // rest of the file // (...) This way I can leave my AS code as it is, refering to game. Now I can compile without errors. I am not sure if it actually works as that would require uploading a new version to Kongregate, but at least there are no error messages this way. |
| ||
Hmm, interesting. Does your tutorial .as file work for you with absolutely zero modification after this change? Even though this certainly fixes the unknown 'game' object errors that I got around by just changing 'game' to 'this' directly in my .as file, I still need to change security.allowDomain(apiPath) to this.security.allowDomain(apiPath) to get it to compile without errors. Using game.security.allowDomain(apiPath) still fails to compile with the error "Access of possibly undefined property security through a reference with static type MonkeyGame". I wonder if that's significant. But even when I use this.security.allowDomain(apiPath) to make the compiler error go away, I end up with TypeError: Error #1010 at runtime. What version of Monkey are you using? I'm on v67f. Edit: Never mind, you said v69 in your other post. I'll update to that now and see if it changes anything. |
| ||
Just in case it helps anyone else who looks at this; I added: import flash.system.Security; to the top of my kongregate.as file to get around the security issue PoliteProgrammer mentions. Foppy - thanks for the tutorial in the first place! Much appreciated :D |
| ||
Aymes, thanks for the help! Sorry for not responding before, PoliteProgrammer. I have to admit I am a bit out of Monkey. |