How to unload an external SWF file from a SWFLoader component in Adobe Flex?

I have an application that downloads external SWF files and plays them in an Adobe Flex / Air application through the SWFLoader Flex component . I am trying to find a way to unload them from a button click event. I have google'd far and wide, and no one seems to be able to do this without hacking. The code combination that I see uses:

swfLoader.source = ""; // Removes the external link to the SWF.
swfLoader.load(null); // Forces the loader to try to load nothing.
// Note: At this point sound from the SWF is still playing, and
// seems to still be playing in memory.
flash.media.SoundMixer.stopAll();
// Stops the sound. This works on my development machine, but not 
// on the client's.

If the SWFs are closed (hidden) this way, the program will eventually crash.

Any ideas? I found a lot of posts in different forums with people having the same problem. I assume that I will get one wrong / incomplete answer here, and my post will sink into oblivion, as usual, but anyway, thanks in advance!

1: SWF-, . SWF, Flex, Flex? SWF -?

+3
7

... Flex?

, , Flash . Loader.unloadAndStop() FP10 (AIR 1.5), , , , , Loader.unload(). ( , 100%, , , , .)

, , - , , - dispose(), , , unload() it. , , swf. .

, .;)

+6

, SWF , Flash Player 10, . , , , , , . ( Flash, , ), , .

, , . Flash, , , - , Flash , , . Flash-, , .

+2

swfLoader.autoLoad = false;
swfLoader.unloadAndStop();
swfLoader.autoLoad = true;

, .

+2

swf, . :

MovieClip(event.target.content).loaderInfo.addEventListener(Event.UNLOAD, unloadMovieClipHandler);
private function unloadMovieClipHandler(event:Event) : void
{
  SoundMixer.stopAll();                           
} 
+1

SWFLoader mx.modules.

Flex , . : http://livedocs.adobe.com/flex/3/html/help.html?content=modular_3.html. , swf , ( ..). , / , , .

+1

:

try {
   new LocalConnection().connect('foo');
   new LocalConnection().connect('foo');
} catch (e:*) {}

. SWF , - , .

GC, , , , Flash Player 10 :

unloadAndStop

: http://www.gskinner.com/blog/archives/2008/07/unloadandstop_i.html

, , , .

0

, , Loader. swfLoader.load(null) , URLRequest. , null . , , , . .


var loader:Loader = new Loader();
var request:URLRequest = new URLRequest('test.swf');
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoad, false, 0, true);

function onSwfLoad(e:Event):void { addChild(loader); loader.contentLoaderInfo.addEventListener(Event.UNLOAD, onLoaderUnload, false, 0, true);

loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoad, false); } function onLoaderUnload(e:Event):void { trace('LOADER WAS SUCCESSFULLY UNLOADED.'); } //Now to remove this with the click of a button, assuming the buttons name is button_mc button_mc.addEventListener(MouseEvent.MOUSE_DOWN, onButtonDown, false, 0, true);

function onButtonDown(e:MouseEvent):void { loader.unload(); loader.contentLoaderInfo.removeEventListener(Event.UNLOAD, onLoaderUnload); //When you want to remove things completely from memory you simply set their value to null. loader = null; button_mc.removeEventListener(MouseEvent.MOUSE_DOWN, onButtonDown); }

, , , , , , , .
0

Source: https://habr.com/ru/post/1697352/