Groups | Blog | Home
all groups > flash actionscript > september 2007 >

flash actionscript : Removing display classes at runtime (AS3)


Lujunq
9/11/2007 8:17:40 PM
Hi, I wrote a class that implements a simple FLVPlayback component with some
other methods. I create instances of this class at runtime "inside" an array
and add them to a visible layer like this:

this.imageArray[index] = new videoImage(iWidth, iHeight);
this.imageLayer.addChild(this.imageArray[index]);

This works ok and the video loaded is correctly placed on screen. However, it
seems that I'm unable to remove these instances. I can, indeed, remove them
from the display, but the movie still plays, since I can still hear it sound.
I'm doing this:

this.imageLayer.removeChild(this.imageArray[index]);
delete this.imageArray[index];
this.imageArray.splice(index, 1);

I also tryed to set the class instance to null like this, but the problem is
the same:

this.imageLayer.removeChild(this.imageArray[index]);
this.imageArray[index] = null;
this.imageArray.splice(index, 1);

How can I completely remove these instances when I don't need them anymore?
Lujunq
9/12/2007 2:41:07 PM
In fact, by checking again and agian, I found that the class is in fact
removed. The problem is about the FLVPlayback component, that is kept even if
the class is removed. Using another code I found that I'm unable to remove an
instance of a FLVPlayback defined in a class... Is there a way do do this?
SymTsb
9/12/2007 6:03:24 PM
Before removing a class you must remove every hard reference to its children
first. This will add them to Flash trash and they will be sent to garbage
collection by the player. It is not enough to simply delete the class.
Lujunq
9/13/2007 4:42:02 AM
Hi, I didn't get. You mean I must go through the instance and remove all of its
properties/methods before removing it?

In fact, as I noticed, the proble isn't related to remove the class, taht now
I know is corretcly removed. The problem is about the FLVPlayback component
removal.

SymTsb
9/13/2007 8:28:49 PM
a typical class has global variables and methods and things of that nature.
I'm not sure about how you built your class but I'm guessing that you put
something along the lines of

var myflvpb:FLVPlayback;

before the declaration of the constructor and then initiating using new later
on in your clip. These kinds of declarations are create global variables (hard
references) which often have listeners etc included. The listeners and the
like have to removed and null'ed out so that no hard reference still exists so
that Flash will run it through garbage collection.
Lujunq
9/18/2007 5:40:57 PM
AddThis Social Bookmark Button