Admittedly, FlashPunk is still an engine I have yet to dive into myself, however, I am heavy into AS3 game dev.
As such, we recently ran into a significant issue w FlashPunk when loading FP games into our Flash-based game platform (so child SWF into parent SWF). One of the restrictions of this situation is strict adherence to Flash best practices regarding the use of stage vs root. Normally, this difference between these two is nil when loading your game from a standard HTML web page. However, when loading your game into a parent SWF, the differences are serious and tragic.
The issue is every SWF has it’s own local root object, but there is only ONE common stage. This means, that if you were load your game’s SWF in a parent SWF, say our platform, which just happens to be full browser window sized, and, for example, we center your game smack in the middle all nice and tidy, if you add a display object at (0,0) to the stage, instead of being added to the upper left corner of your game, it’s added to the upper left corner of the whole bloody browser window (i.e. the 0,0 position of the parent).
If you were to add that same display object to the root of your game’s swf, it will appear exactly where it should. This is because each SWF has a root, but they all share a stage. So, best practice (defined by Adobe, not us), is to always use root, as stage will vary from situation to situation but root will always be appropriate.
Unfortunately, it turns out that FlashPunk exclusively uses the stage. For everything. From the get go. Thus, every game made using FlashPunk (and, as an extension, HaxePunk, because it’s directly ported from FP), breaks when it’s loaded into a parent SWF.
Thankfully, we enlisted some help and have found a solution, which can be found here: http://github.com/playvue/DOFlashPunk.
This approach has been tested and confirmed to work in the situation described above, but I thought I’d open it up to the FP Pros for some honest testing, review, confirmation and feedback.
Please let us know what you think!
Keith @ Playvue