4 Replies Latest reply on May 28, 2007 4:09 AM by -Wilco-79-

    Listener problem when "unloading" externaly loaded SFW's

      Sorry for double post!

      While loading an external SWF in to an Flex application is easy, removing it again seems to bring a few problems.
      What i want to acomplish is the following: Make a portfolio website in Flex, in which i can show images, movies and SWF's.
      So I want to be able to load a SWF i made (which is not part of the application) made with flex or flash.

      The problem that i'm having is that if the loaded SWF adds listeners to the stage or to it self, the listeners keep calling functions even after the SWF was removed using unload or by loading different content.

      I've tried this with both AS3 and the flex framework and with SWF's created in both flex (using the flex framework) en flash.

      Setting the listeners with weak reference seem to work for AS3 (Loader).
      But this is missing the point, since i want to be able to load just any SWF file (Flash 9, AS3 offcourse).

      Any help would be welkom
        • 1. Re: Listener problem when "unloading" externaly loaded SFW's
          buabco Level 1

          Garbage collector will not destroy your swf or any other object for that matter until all reference to it has been destroyed. This include events, so each time you add a listener to an object you are also adding a reference to the listening object.

          This means that a polite object must remove its event listeners once it stop needing them, in your case I would add a REMOVED event listener to my SWF that will do the cleanup of all the listeners that this swf is using to the stage and any other object.
          • 2. Re: Listener problem when "unloading" externaly loaded SFW's
            -Wilco-79- Level 1
            If i made something thats not supposed to be part of the application, but i still want to load it into my portfolio website.
            I have to edit it first to make a remove listeners function??

            There must be a way to work around this.

            In flash 8 AS2 i never had problems with this and i could load just ANY swf file (maybe set it to _lockroot=true) and it worked!

            Is there a way to create a automatic listener removal function?
            • 3. Re: Listener problem when "unloading" externaly loaded SFW's
              buabco Level 1
              Well you have to ways to go arround this:

              You can remove the event listeners when you unload the movieclip from the SWFLoader, or you can impement an UNLOAD event listener in the containing SWFLoader or the stage, the UNLOAD event bubbles witch means that you'll be able to catch this event and remove the listeners. Still, you'll have to know witch events the swf has registered to, I haven't been able to find any function to know witch events a specific object is listening to. I don't think there is :(.

              On the other hand any swf compiled with flash 8 or prev. shouldn't have this problem since it will work in a different virtual machine... still you wont be able to control them ether.

              • 4. Re: Listener problem when "unloading" externaly loaded SFW's
                -Wilco-79- Level 1
                After some searching in the doc's and on internet i came to the same conculsion :(
                This kinda sucks.......
                Any way, Thx for your help!