5 Replies Latest reply on Nov 8, 2007 12:25 PM by kglad

    AS3 close() method

    "B" Level 1
      I have been working on this file for 9 hours straight now. I cannot for the life of me figure out how to get the close method to work so that if a viewer clicks on a button to view a movie (the movie loads in as an external swf), but then changes their mind and clicks on another button to view a different movie, then the first one will stop downloading.

      I have tried a million different things and nothing is working. And, yes, I've tested it on a server since I've read that the close method doesn't work in Simulate Download.

      Does anyone have any idea how to get the close method to function properly? I've done so many searches on the internet and can't find anything that applies.

      I've tried close() and removeChild() and unload() and nothing works to stops the download. I've tried putting those methods in the function that runs when a button to load the external movie is clicked... I've tried putting them in an addEventListener/INIT function... and an addEventListener/UNLOAD too.

      I also have to figure out how to make sure that the proper movie is closed/removed/unloaded. I've tried a few things including referencing target/currentTarget/content/loader/etc in the addEventListener functions.

      Error, errors errors and nothing works.

      Any ideas on how to get this to work would be appreciated.
        • 1. Re: AS3 close() method
          kglad Adobe Community Professional & MVP
          did you try using the close() methods on the line just above your load() methods?
          • 2. Re: AS3 close() method
            "B" Level 1
            Here's what I have:

            • 3. Re: AS3 close() method
              kglad Adobe Community Professional & MVP
              i don't see a problem with that, though you don't need to use a try..catch and you're probably adding myLoader to the empty repeatedly which is problematic.
              • 4. Re: AS3 close() method
                "B" Level 1
                I put the close method inside a try because if the movie is already finished downloading, then an error message occurs.

                If I'm referencing the myLoader object for the close/uload/remove, isn't that (once it all actually works) going to cause a problem? As in, as soon as something loads it will immediately be closed/unloaded/removed. It seems to me that I would need to reference the previous movie clip that was loading prior to the newest one being loaded. But every way I've tried it just gives me errors.

                Also, I was reading on the actionscript.org forum and someone said he got the close method to work by referencing his movie clips via an absolute path rather than relative. Meaning, instead of

                var myRequest:URLRequest = new URLRequest("movieOne.swf")

                he did...

                var myRequest:URLRequest = new URLRequest(" http://www.serverWebAddress.com/movieOne.swf")

                And he said it worked. I have yet to test this, but I'll report back to whether it works or not.

                Also, the addChild could be problematic because it sits inside the function? I thought so too, but then my logic was that each time that function runs it will be closed/uloaded/removed anyways. I'm not sure if that's even logical at this point. I'm working on 2 hours of sleep. I will, however, place it outside of the function and see what happens.

                Hey question... is it possible to monitor the display list? Sure would be helpful in checking to see when things are being added and removed. In that way, I can see if some of my logic in having things added/removed is working or not.

                Thank you for your replies.

                • 5. Re: AS3 close() method
                  kglad Adobe Community Professional & MVP
                  ok, on the try..catch.

                  i have no trouble using a relative path with the close() method.

                  the addChild() is a problem because you're repeatedly adding your loader. you only need to add it once to the display list. executing the close() method doesn't remove your loader from the display list. it just stops any open streams.

                  yes, you can monitor the display list, but i don't think that will help you. you're going to see your loader is in the display list. and if you don't change your code you're going to see your loader is added to your display list multiple times.

                  you probably want to check the url of your loader's contentloaderinfo property. this property is accurate after the first progress event is dispatched by your loader's contentloaderinfo property.