5 Replies Latest reply on Sep 18, 2007 10:40 AM by Lujunq

    Removing display classes at runtime (AS3)

    Lujunq
      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?
        • 1. Re: Removing display classes at runtime (AS3)
          Lujunq Level 1
          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?
          • 2. Re: Removing display classes at runtime (AS3)
            SymTsb Level 2
            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.
            • 3. Re: Removing display classes at runtime (AS3)
              Lujunq Level 1
              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.
              • 4. Re: Removing display classes at runtime (AS3)
                SymTsb Level 2
                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.
                • 5. Re: Removing display classes at runtime (AS3)
                  Lujunq Level 1
                  Besides the listeners, are there more properties/methods that I have to manually remove to destroy my flvplayback instance? It still remains on my stage after removing all the listeners associated...