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.
8 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
Hi Yoshihiro!
Thank you very much for such an amaizing class! Awesome!
I noticed only one issue: I can’t reach the very last frame of loaded SWF (contains only animated graphics; no AS code).
The property “totalFrames” is correct (49 frames total), but despite of it I can’t jump to the last 49th frame. I mean I can code “gotoAndStop(49)” but it goes only to the next to last one (48th).
I appreciate any help. Tank you! Cheers!
Ruppo
Please, have a look at this example: http://ruppo.tk/partners/netkata/turboekoman/test.swf
The progress bar should reach the end of the container (49th frame) but it only goes to the 48th
ps. loaded SWF is Flash4
oh! and I forgot: this is the movie loaded in:
http://ruppo.tk/partners/netkata/turboekoman/scena11.swf
As you can see: the progressbar reaches the end of container.