Search code examples
androidactionscript-3wrapperloader

When loading AS2 swf into AS3 with swfLoader on Android skips through frames like mad


I'm trying to make an AS3 wrapper to port a collection of old flash games(AS2) to my Android phone. I have successfully loaded and run(in the sim/run window ctrl+Enter in CS5.5) the old AS2 .swf with the following code:

// This is the Loader instance that will load your SWF.
var swfLoader:Loader = new Loader();

// URLRequest points to your external SWF
var swfFile:URLRequest = new URLRequest("ha2.swf");

//create the container Movie Clip to load swf
var container:MovieClip= new MovieClip();

// Assign an event listener so that Flash informs you when the SWF has been loaded.

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadedHandler);

function swfLoadedHandler(e:Event):void {
    trace("swf loaded");
//(e.target.content).stop();//returns null reference for stop function

}

swfLoader.load(swfFile);

//just add the loaded swf to container
container.addChild(swfLoader);
//add container to the stage and make it visible

addChild(container);

This runs fine on PC and loads up the swf as it should, but once I publish it to android it skips through the frames of the AS2 application super fast in a loop instead of following the scripts like it does in the sim.

Any ideas? And yes, I realize these games would run quicker if re-coded to AS3, but there are a lot of them and I'd like to preserve the originals and make the shell as a more dynamic(albeit less efficient) solution.

Thanks.


Solution

  • Actionscript 2 is not supported on AIR. Running an app in the AIR device simulator is NOT the same as running an app on a real device. I've done something similar trying to load an AS3 swf in an AIR app on iOS. The emulator let me do it, but a real iOS device gives a warning that it is not supported.
    What you're seeing is all frames animating as if there was no script in your movie (as the AIR player apparently ignores all ActionScript code).
    Recoding your games to AS3 is the only solution for Android, and if you want to support iOS too, your only option is to compile them all into one app, as on iOS it is not even allowed to load any external movies that have code in them.