I am developing an IOS app using Adobe AIR, Flash and ActionScript 3 and I have divided sections up into separate SWF files. I have successfully gotten the app to load external
I was able to solve the problem of reloading SWF's w/o ABC (no code!), I explain it all on my blog (http://www.eqsim.com/blog/?p=400) but also simply give the code on StackOverflow: Load and reload external SWF in AIR for iOS wf-in-air-for-ios/22046009#22046009
Now Adobe has a solution for separating code from the SWF, and loading the SWF externally. However, we addressed it prior to AIR 3.5 by making a class for the code only, then loading the SWF and in the code class, setting a link to the loaded SWF. When we needed to update to 4.0, the SWF reloading, even pure SWF assets, was not working in all situations, so we plugged away to find the solution I reference above.
You could have a static class that functions as a cache.
The cache might look something like this that I made for a menu system:
package com.rs2014.managers{ import flash.display.MovieClip; import flash.utils.Dictionary; import flash.events.Event; import flash.events.EventDispatcher;
import com.events.MenuManagerEvent;
import com.menus.MenuBase;
import com.components.MenuLoader;
import com.MenuIdents;
public class MenuManager extends EventDispatcher
{
private static var instance:MenuManager
private static var allowInstantiation:Boolean = true;
public static function getInstance():MenuManager
{
if(!instance)
{
instance = new MenuManager();
allowInstantiation = false;
}
return instance
}
private const MAX_MENUS:uint = 8;
private var menuCache:Dictionary = new Dictionary()
public function MenuManager()
{
if(!allowInstantiation)
{
throw(new Error("please use the getInstance() method to obtain a handle to this singleton"));
}
}
public function getMenu(menu:String):void
{
if(menuCache[menu])
{
//This pulls from the cache if it's already been loaded before
dispatchMenu(null, menuCache[menu]);
}
else
{
//MenuLoader is a simple wrapper for Loader
var newLoader:MenuLoader = new MenuLoader();
menuCache[menu] = newLoader;
newLoader.addEventListener(Event.COMPLETE, dispatchMenu);
newLoader.source = menu;
//trace("setting up loader with source = "+menu);
}
}
private function dispatchMenu(e:Event = null, menu:MenuBase = null):void
{
if(e)
{
e.target.removeEventListener(Event.COMPLETE, dispatchMenu);
//trace(e.target.content);
//trace(e.target.content as MenuBase);
menuCache[e.target.source] = menu = e.target.content as MenuBase;
//trace(menu);
}
if(!menu)
{
throw(new Error("MenuManager Error: dispatchMenu called without menu to dispatch"));
}
this.dispatchEvent(new MenuManagerEvent(MenuManagerEvent.MENU_READY, menu))
}
}
}