PDA

View Full Version : Completely remove an SWF



aurelplouf
November 11th, 2008, 03:52 AM
I know this has been asked and I read a lot of articles and forum threads and I am still really confused.

Currently I am building a website with a couple of menu buttons which load external SWF.

Every time i click on another button, i remove the SWF child. But I quickly realized that in AS3 it does not completely remove the swf.

Therefore I want to remove the listeners from these external SWF when I click on another menu buttons.
I also wish to remove all the Display Objects from the SWF.

in my AS I have the following:

My mainStage.as


public function inViewBtnClick(event:MouseEvent):void {
removeChildAt(2);


innerRingBtn.buttonMode=true;
outRingBtn.buttonMode=false;
var planeTestA:URLRequest=new URLRequest("planeTestA.swf");
var planeTestALoader:Loader=new Loader;
planeTestALoader.load(planeTestA);
addChildAt(planeTestALoader,2);
removeChildAt(3);
addChildAt(outRingBtn,3);
outRingBtn.x=22;
outRingBtn.y=710;
outRingBtn.buttonMode=true;
outRingBtn.mouseChildren=false;
}
public function outViewBtnClick(event:MouseEvent):void {

removeChildAt(2);


outRingBtn.buttonMode=true;
innerRingBtn.buttonMode=false;
var planeTestB:URLRequest=new URLRequest("planeTestB.swf");
var planeTestBLoader:Loader=new Loader;
planeTestBLoader.load(planeTestB);
addChildAt(planeTestBLoader,2);
removeChildAt(3);
addChildAt(innerRingBtn,3);
innerRingBtn.x=22;
innerRingBtn.y=710;
innerRingBtn.buttonMode=true;
innerRingBtn.mouseChildren=false;
}


and in one of my external SWF I have this from the AS file (planeTestA.as)



private function initListeners():void {
//setting up listeners

addEventListener(Event.ENTER_FRAME, render);
planeA.addEventListener(InteractiveScene3DEvent.OB JECT_CLICK, onShowcaseClickA);
planeA.addEventListener(InteractiveScene3DEvent.OB JECT_OVER, onShowcaseOverA);
planeA.addEventListener(InteractiveScene3DEvent.OB JECT_OUT, onShowcaseOutA);

planeB.addEventListener(InteractiveScene3DEvent.OB JECT_CLICK, onShowcaseClickB);
planeB.addEventListener(InteractiveScene3DEvent.OB JECT_OVER, onShowcaseOverB);
planeB.addEventListener(InteractiveScene3DEvent.OB JECT_OUT, onShowcaseOutB);

planeC.addEventListener(InteractiveScene3DEvent.OB JECT_CLICK, onShowcaseClickC);
planeC.addEventListener(InteractiveScene3DEvent.OB JECT_OVER, onShowcaseOverC);
planeC.addEventListener(InteractiveScene3DEvent.OB JECT_OUT, onShowcaseOutC);

planeD.addEventListener(InteractiveScene3DEvent.OB JECT_CLICK, onShowcaseClickD);
planeD.addEventListener(InteractiveScene3DEvent.OB JECT_OVER, onShowcaseOverD);
planeD.addEventListener(InteractiveScene3DEvent.OB JECT_OUT, onShowcaseOutD);

planeE.addEventListener(InteractiveScene3DEvent.OB JECT_CLICK, onShowcaseClickE);
planeE.addEventListener(InteractiveScene3DEvent.OB JECT_OVER, onShowcaseOverE);
planeE.addEventListener(InteractiveScene3DEvent.OB JECT_OUT, onShowcaseOutE);
}


So the big question is How do I remove the eventListener ENTER_FRAME in my planeTestA.swf from my mainStage.as

Side notes: I currently use Flash Player 9. I heard some nasty stuff from this page
http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html


Thank you in advance for the help ;)

Best

Aurel

weaponsofwar
November 11th, 2008, 04:01 PM
you should be able to remove the swf from memory entirely using the techniques in this example:

http://www.kirupa.com/developer/flashcs3/managing_mc_instances_pg2.htm

alternatively you could use this:


var oMyObject:* = whateverObject;
oMyObject.parent.removeChild(oMyObject.parent.getC hildByName(oMyObject.name));
oMyObject = null;
trace(oMyObject);

^ posted along with another function to remove all children of a given object in:
http://www.kirupa.com/forum/showthread.php?t=312653

I'm chasing down total removal of objects from memory as well and thought this would work based on senocular's post regarding: removeChild(getChildByName("instanceName"))

still haven't verified if this is iron clad or not.

good luck.

aurelplouf
November 11th, 2008, 07:45 PM
Thank you for the reply.

From what I understand, everytime I load an SWF, I should reference the the SWF object into an array and then in order to remove it, I remove the array as a DisplayObject ?

My question is the following then:

1) From the tutorial http://www.kirupa.com/developer/flashcs3/managing_mc_instances_pg2.htm

it uses removeChild in order to clear the Array. Therefore, does it remove completely the SWF as a DisplayObject?

2) Will the loops and Listeners from the SWF remain on stage after removing the DisplayObject

3)If push my array with the movieclips i reference into, will i be able to keep a structure of depth with (addChildAt or getChildAt)?

AS3 really have two problems in my opinion:

Keeping a Movieclip or SWF in an organized way and keep from within the DisplayObjects and the code from overlapping with the rest. And eventhough Adobe says that depth management is more user friendly in AS3 because there is an automatic side to it, I find it extremely annoying.

But for this project, I need to use AS3 :/

I will try to look into my problem and if I find a good way to clear my memory leak, I will post it here :)

Best,
Aurel

aurelplouf
November 11th, 2008, 10:18 PM
So since I am loading in some external SWF which have heavy Actionscript in it... I decided to load the SWF from MovieClips in my Library.

Then from the mainstage I load the movieClips that hold the SWF and add them to an array.

Then I use whenever i click another button



function RemoveItems() {

for (var i:int = 0; i < listOfMovieClips.length; i++) {

var itemToRemove:DisplayObject = listOfMovieClips[i];
this.removeChild(itemToRemove);

}
listOfMovieClips = new Array();

}


Well it does work better than removeChild indeed.

But the DisplayObject is not visible but still there, and the Actionscript from the SWF still remain.

Therefore my memory keeps on stacking these objects and their actionscript. After clicking on buttons a couple of times, my movie gets really slow.

Is there any ways to completely delete these stacking objects and ENTER_FRAME Events ?

thanks