Skip to main content
emmau10371638
Inspiring
February 27, 2016
Answered

Are remote SWF faster than local SWF on AIR IOS app because I can 't use the unload code.

  • February 27, 2016
  • 1 reply
  • 954 views

Are remote SWF faster than local SWF on AIR IOS app because I can't use the unload code on AIR IOS .

my local code:

stop();

import flash.net.URLRequest;

import flash.system.ApplicationDomain;

import flash.system.LoaderContext;

import flash.filesystem.File;

import flash.filesystem.FileMode;

import flash.filesystem.FileStream 

go_level_2.addEventListener(MouseEvent.CLICK,level_2);

function level_2(event:MouseEvent){

  

var loader2:Loader = new Loader();

var loaderContext2:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);

var file2:File=File.applicationDirectory.resolvePath("level2.swf");

loader2.load(new URLRequest(file2.url), loaderContext2);

addChild(loader2);

}

Because this works not for me, because i can't unload the SWF file en the app becomes slow, i  will put the SWf''s on a remote place.

But I can't  imagine what happens when i loaded the SWF file from remote. stays it on the server or stays it on my app when i unloaded it, and the app also becomes bigger. I hope you can help me because i  went on the internet for a week and don't now how to go on further.

This topic has been closed for replies.
Correct answer MickaelKicker

thanks for reply but i have the next problem:

go_level_2.addEventListener(MouseEvent.CLICK,level_2);

function level_2(event:MouseEvent)

{

var loader2:Loader = new Loader();

var loaderContext2:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);

var file2:File=File.applicationDirectory.resolvePath("level2.swf");

loader2.load(new URLRequest(file2.url), loaderContext2);

loader2.addEventListener("LEVEL_2",true);

addChild(loader2);

}

function finishLevel2(event:Event):void

{   var loader2:Loader;

loader2=event.target.loader;
loader2.parent.removeChild(loader2);
loader2.unloadAndStop();

}

//And the code in next level to remove level before add another.

var loader2:Loader;

function finish_game(event:Event):void

{

dispatchEvent(new Event("LEVEL_2",true));

}

I have a Main_SWF within 10 levels_SWF's.

I tried several codes but not one of these unload te previous game.

And the game begin slower and slower.

The last part of  developing a game for IOS is a "nightmare" i think.

i test the code on iOS simulator.

I hope you can help me.


I had a similar problem, but not on iOS.

Maybe my solution could work for you too, though.

The problem was coming from this line:

new LoaderContext(false, ApplicationDomain.currentDomain);


Do not reuse the same application domain, or you'll never be able to get rid of the definitions, and therefore the loaded SWF.

Instead, make a new application domain, child of the current domain, keep track of it and dispose it along with the rest of the SWF when you're done.


Example :

var loader2:Loader = new Loader();

var appDomain2:ApplicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);

var loaderContext2:LoaderContext = new LoaderContext(false, appDomain2);

var file2:File=File.applicationDirectory.resolvePath("level2.swf");

loader2.load(new URLRequest(file2.url), loaderContext2);

addChild(loader2);

Then

function finishLevel2(event:Event):void

{  

   var loader2:Loader;

loader2=event.target.loader;
loader2.parent.removeChild(loader2);

loader2.unloadAndStop();

appDomain2 = null;

}

Note that the definitions of the loaded SWF's classes will only be available from the new application domain...

1 reply

kglad
Community Expert
Community Expert
February 27, 2016

are you using unloadAndStop() instead of unload()?

emmau10371638
Inspiring
February 27, 2016

Packaging and loading multiple SWFs in AIR apps on iOS

Loader.unload() & Loader.unloadAndStop()

The behavior of Loader.unload() and Loader.unloadAndStop() on iOS is below. When either of these functions is called the following will happen:

  1. The contentLoaderInfo property of the Loader object will become null
  2. Any assets that are loaded with the secondary SWF will be unloaded.
  3. Any references to AS classes in the loaded SWF remain in memory, and new objects of those AS can be created. This is different from the behavior on other platforms.

Thanks voor the reply. But i didn't understand the answer because this information above is from the Adobe

blog.

kglad
Community Expert
Community Expert
February 27, 2016

use unloadAndStop().