Skip to main content
El_Arcon
Inspiring
August 22, 2010
Answered

[ASK]how to remove object from display list and memory which added dynamicly

  • August 22, 2010
  • 2 replies
  • 1988 views

Hi there everyone,

i have a question which i hope you guys can help me with,so the question is :


" how do we remove object( sprite which has an external swf as it's child ) from display and more importantly from memory yet we still can use the same variable to add  another object (yes another sprite like the one we removed yet has different content).., "

i did tried the removeChildAt thing it did remove all the child from the display list but i still can hear sound from video running.

here is small scale code of what i'm doing (sorry that i can only give you chunk code of loading and adding)

// var SWFList:XMLList; //used to hold a list of all external swf source,atribute and etc
// var totalSWF:int; //hold the total number of external swf there is to be loaded

// var swfLoader:Loader; //instance of loader class used to load the external swf

function loadSWF():void
{
    for (var i:Number; i < totalSWF; i++ )

    swfLoader = new Loader();
    swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE , onSWFLoadComplete);
    swfLoader.load(new URLRequest(SWFList.@source));
}

function onSWFLoadComplete(e:Event):void

{

     this.stage.addChild(e.target.content);

}

and also if you can give an example of a good method of dynamicly adding object to the stage i would really appreciate it cause i suspect mine's are bad method to used.

thanks everyone.

This topic has been closed for replies.
Correct answer kglad

hi kglad tanks staying n replying in this thread.,

well i don't understand where to put swfLoader.unload(); and how things work with that because i just add all those external swf by one Loader (swfLoader) and after it's load complete i add it to the stage by using e.target.content and adding new line which is

swfLoader = null;

and how do i remove all eventListener of those external swf cause i did some searching with google and know that before removing the object we need to ensure that those object has no event listener attached to it..,

i tried your suggestion:

function clearScreen():void
{
    for(var i:int =0; i< stage.numChildren; i++)
    {
        stage.removeChildAt(i);
    }
    swfLoader.unload();
}

but it still leave the video player running..,

i'm really confused by this..,


if you were publishing for fp 10, just use unloadAndStop().

i assume you're not publishing for fp 10 so you should use something like:


function clearScreen():void
{
var mc:MovieClip=MovieClip(swfLoader.content);

mc.yourflvintheloadedswf.stop();

mc.mcinyourloadedswfthathasalistener.removeEventListener(MouseEvent.CLICK,whateverF);

//etc

    swfLoader.unload();
}


2 replies

El_Arcon
El_ArconAuthor
Inspiring
August 24, 2010

cananyone help me with this???

kglad
Community Expert
Community Expert
August 24, 2010

i just showed you.

what is it you don't understand?

El_Arcon
El_ArconAuthor
Inspiring
August 24, 2010

hi kglad tanks staying n replying in this thread.,

well i don't understand where to put swfLoader.unload(); and how things work with that because i just add all those external swf by one Loader (swfLoader) and after it's load complete i add it to the stage by using e.target.content and adding new line which is

swfLoader = null;

and how do i remove all eventListener of those external swf cause i did some searching with google and know that before removing the object we need to ensure that those object has no event listener attached to it..,

i tried your suggestion:

function clearScreen():void
{
    for(var i:int =0; i< stage.numChildren; i++)
    {
        stage.removeChildAt(i);
    }
    swfLoader.unload();
}

but it still leave the video player running..,

i'm really confused by this..,

kglad
Community Expert
Community Expert
August 22, 2010

you want to reuse swfLoader?

El_Arcon
El_ArconAuthor
Inspiring
August 23, 2010

yes i want to reuse swfLoader and also i want to know the correct way of removing the the object that i already added to the stage

kglad
Community Expert
Community Expert
August 23, 2010

if you're publishing for flash 10, use:

swfLoader.unloadAndStop();

and null all references to swfLoader.content, if there are any and remove any listeners applied to swfLoader.content, if there are any.

for flash 9, use:

swfLoader.unload();

do the above AND explicitly stop all streams in the loaded swf.