0
In my project, I am trying to save all the swfs loaded in memory to make users free of delay... I can’t and I don’t want to use "Loader.unloadAndStop()" in the Loader.
I am saving all content uploaded within an Object.
For example:
var CacheSWF:Object = new Object();
var CurrentSWF:String;
function GetSWF(swf:String):void {
this.CurrentSWF = swf;
if (this.CacheSWF[this.CurrentSWF] != null) {
this.removeAllChildren();
stage.addChild(this.CacheSWF[this.CurrentSWF]);
} else {
var ldr:URLLoader = new URLLoader();
ldr.dataFormat = URLLoaderDataFormat.BINARY;
ldr.addEventListener(Event.COMPLETE, this.loadBytesSWF);
ldr.load(new URLRequest(this.CurrentSWF));
}
}
function loadBytesSWF(evt:Event):void {
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, this.saveSWF);
ldr.loadBytes(ByteArray((evt.target as URLLoader).data));
}
function saveSWF(evt:Event):void {
this.removeAllChildren();
this.CacheSWF[this.CurrentSWF] = MovieClip(Loader(evt.target.loader).content);
stage.addChild(this.CacheSWF[this.CurrentSWF]);
}
function removeAllChildren():void {
while (stage.numChildren > 0) {
stage.removeChildAt(0);
}
}
But I’m having some kind of conflict when I try to load another swf. The second Movieclip loaded runs the maintimeline of the first Movieclip loaded. I have no idea how to fix this.
Example:
this.GetSWF("file1.swf"); //Eu tenho o MovieClip e MainTimeLine corretos
//Faço algo...
this.GetSWF("file2.swf"); //Eu tenho o MovieClip correto mas o conteúdo executa a função MainTimeLine do "file1.swf"
If there is no way to save the way I want, how can I clean it (the Loader) without using "Loader.unloadAndStop()" or "Loader.()"?
- Based on the Adobe library, the Loader.() does not work for content uploaded by Loader.loadBytes();
- I can’t use Loader.unloadAndStop() because this function does not exist for Flash 9 (the destination of my project).
Welcome to Stack Overflow in English. Please click on edit and translate the question.
– Luiz Augusto
Carlos, I already had a lot of problem with relation and a while ago I gave up trying to give "Unload" in the swfs loaded by loadBytes. My guess is that once you load an external SWF, the libraries and sources you use, including images and videos, are merged with the SWF you are loading. If you give Loader.Unload(), only the code contained in its main structure will be downloaded, the rest will remain.
– bio
On the other hand, Loader.Unload() works great when loaded with Loader.load(). This particularity somewhat restricts the features you can use in the external SWF, but it is exactly this bubble that is downloaded when you call Loader.Unload(). To try to get around this, you can take a look at the object Applicationdomain.
– bio
The problem is that I have no alternative. The destination of my application is AIR Android. Using only Loader.load() I cannot load external swfs, just as I illustrated above. Otherwise I get a security breach error even using Loadercontext.
var appDomain = new ApplicationDomain();
var appContext = new LoaderContext(true, appDomain);
appContext.applicationDomain = ApplicationDomain.currentDomain;
appContext.checkPolicyFile = false;
appContext.allowCodeImport = true;
appContext.allowLoadBytesCodeExecution = true;
– Carlos Loureiro