ForcibleLoader: Loads AVM1 SWF files into AVM2
By default, Flash Player loads a movie as an instance of the AVM1Movie class if you load a SWF file with a version lower than 9 by the Loader class in AS3. This means you can’t touch any MovieClips in the such SWF file through the Loader. But sometimes we want to do it. I created a solution to this problem – ForcibleLoader
var loader:Loader = Loader(addChild(new Loader()));
var fLoader:ForcibleLoader = new ForcibleLoader(loader);
fLoader.load(new URLRequest('swf7.swf'));
This is how to use it. It loads every SWF file including files under version 9 into the Loader as a AVM2 movie. So now you can access MovieClips in the SWF file through the instance of Loader.
Note: It will not work well if the SWF file contains ActionScript2 because ForcibleLoader doesn't convert any scripts.
5 Comments
Hi Yoshihiro,
thanks for this very useful class!
In using it, I’ve found a small/ missing feature: SWF files with version 9 but AVM1 script tag won’t be converted to AVM2. To fix this, I’ve modified the lines starting at 97 to the following:
if (version 7) {
flagSWF9Bit(inputBytes);
}
else {
insertFileAttributesTag(inputBytes);
}
cheers and thanks,
till
meh, the comment system seems to strip out html entities. Maybe this version works:
if (version < 9) {
updateVersion(inputBytes, 9);
}
if (version > 7) {
flagSWF9Bit(inputBytes);
}
else {
insertFileAttributesTag(inputBytes);
}
Thank you!
I fixed it.
Thanks, i made a couple changes to your script to handle a byteArray
private function completeHandler(event:Event):void
{
loadBytes();
}
public function loadBytes(bytes:ByteArray=null):void
{
var inputBytes:ByteArray;
if (!bytes)
{
inputBytes = new ByteArray();
_stream.readBytes(inputBytes);
_stream.close();
} else
{
inputBytes = bytes;
}
w00t!
One more thing I noticed, that i loaded in a clip and it can’t seem to go to go back again to the second frame of a 2 frame movieclip. I am using your code to work with pdfToSWF… When there are only two frames, i can go forward the first time, just not back, however, 3 frames seem to work fine. haven’t tested others amounts yet.
Also, the loaded clip’s height is 3000000 pixels wide and tall… some weirdness there.
Thanks for your time