I found several info on how to load one or more external SWF files, packaged with my AIR iOS App, the actual working code is:
var myUrlRequest:URLRequest = new URLRequest(mySWF);
var myLoaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
var loader: Loader = new Loader();
loader.load(myUrlRequest, myLoaderContext);
Object(root).MK.addChild(loader)
It works on Android devices and on Windows PC, but on iOS it loads the external SWFs only the first time. In my project I have several buttons that loads an external SWF, but each button works only the first time.
Any idea? It seems very unuseful if I can't reload an SWF.
If you can't load something a second time, perhaps it would be best to simply cache it and make a point of only loading it once?
A good way to handle this would be to load the SWF files into separate movieclips the first time and then when needing to "load" them anytime after that, just show those movieclips that already have the SWF files loaded in them.
You can't load a SWF file that contains any ActionScript ByteCode (ABC) then unload it and reload it on iOS. If you attempt to do this, the runtime throws error 3764.
I had problems loading SWF's even without code a second time. The solution I found depended on whether the code was from the application area (packaged with the app) or loaded externally (either from the web or downloaded into the caches folder).
I wrote an extended post about here, if you're interested: http://www.eqsim.com/blog/?p=400
In a nutshell, here is my code for setting the path:
var moduleDirectoryPath = "/modules/";
if (externalContent == FROM_CACHE) {
moduleDirectoryPath = File.cacheDirectory.url + moduleDirectoryPath;
} else if (externalContent == FROM_WEB) {
moduleDirectoryPath = "http://our-online-content.com" + moduleDirectoryPath;
}
then here is my code for preparing the path, if the SWF is from the app area or otherwise (cache or web):
if (loadFromApp) {
path = moduleDirectoryPath + module_folder + "/" + module + "?nf="+getTimer();
} else {
path = moduleDirectoryPath + module_folder + "/" + module;
}
Finally, my loading statements:
request = new URLRequest(path);
request.cacheResponse = false;
request.useCache = false;
_lc = new LoaderContext(false, ApplicationDomain.currentDomain, null);
moduleLoader.load(request, _lc);
and now I can load SWF's and reload them (more importantly). Of course the SWF's do not have bytecode in them.