initInjector

Someone in ruFlash user group asked if it’s possible to get rid of errors when loading a SWF which thinks it is the only SWF in the world and there totally must be stage available in its constructor. As you already understood such SWFs fail with Null Access errors.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

This task looks like a great exercise for my epic Scala skills I got trying to understand famous Joa‘s code.

Thanks to apparat and Scala I managed to code a small app which rewrites SWF files and moves all constructor code to a private method which is later subscribed to ADDED_TO_STAGE event.

usage: java -jar initInjector.jar [-c] [-p] <from.swf> [to.swf]
-c — check for references to stage in constructor
-p — inject into parent classes constructors too
If [to.swf] is not specified resulting SWF is saved to <from.swf>

Stable release: initInjector.zip

0.2.1b:

  • Recompiled for Scala 2.8.0

0.2b changes:

  • Fixed several bugs
  • added -p option which also injects init method to parent class constructor
  • Thanks to Joa Ebert who modified apparat for my needs I got rid of half of my code

Thanks to everyone for reporting bugs.