I have an AS3 Air App (Desktop App)- let us call it MAIN that loads a bunch of swfs. So, MAIN loads swfA and then unloads it. MAIN has an event listener that listens to unloading of swfA. Trace shows swfA is unloaded successfully, as the unload event fires. However, the as3 contained within swfA still executes long after swfA is unloaded. How do I know? There is a timer-event in swfA that still executes even though swfA has been unloaded.
Is this a feature or is my code missing anything.
Here is basic code in MAIN
swfLoader.load(new URLRequest("swfA")); // load the SWF file
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onSwfLoad);
swfLoader.contentLoaderInfo.addEventListener(Event.UNLOAD, onSwfUnload);
Here is basic code in swfA
var timer: Timer = new Timer(1000, 60);
timer.addEventListener(TimerEvent.TIMER, onTick);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimeUp);
timer.start();
The desired behavior for the swf to unload and all that ActionScript3 to NOT execute, as unloading the swf, well my understanding of it at least, is that it is unloaded, gone, not here! Thanks for any insight on the matter!
I am providing an updated answer that best worked for me, and I stumbled upon it while I was troublehshooting something else. It turned out that the answer was super easy. Posting answer in case this might be helpful to someone in the future.
It turns out, in AS3, one can use the following method which unloads the swf, AND stops the loaded swf from executing anything in it. This worked for me! I was using the
loader.unload()
When I should have been using the
loader.unloadAndStop(true);