Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
arcanepain

Unloading AS2 SWF content

Recommended Posts

Hi all,

 

Apologies if i'm asking a ridiculous question, trying something nuts, or completely missing something simple, but i've been going at this for hours with no success and i'm getting a little dis-heartened. The magic of actually loading content in via LoaderMax (i'm a long time Greensock user, but have only stepped into the frustrating world of AS3 and as such have only just realised how great SplitText and Loader Max are!) went very smoothly and works better than I could have hoped...it's destroying brought in content that's killing me!

 

I'm using LoaderMax (via the queue functionality) to bring in the SWF - an AS2 swf, which makes good use of TweenLite inside it and has a looping animation. SWF is loaded, fades in, and the loops runs perfectly....went I remove it though, although it completely disappears, the TweenLite animation loop obviously continues in the background (tellingme the SWF isn't being properly removed / garbage collected) as a couple of 'traces' I have in the loop keep firing. As I continue to press the button to load the same SWF, they are obviously stockpiling too - multiple fires of the traces go off, and keep going off. My fear is just that, sooner or later, memory will run out and the whole Flash plugin will fall over. :-(

 

I've scoured the forums here and followed what advice I can understand from the Docs...i've used 'unload' on the queue, 'dispose(true)' and queue=null. If I null the queue or just dispose the whole thing seems to just stop working (ie. nothing loads the second time around). If I unload() it seems to do the trick, as the loop stops firing, BUT when I go to load the SWF again, I just get a blank background - the SWF loads, but its like all its movie clips have vanished. OR TweenLite just isn't firing, hence the stage objects just aren't appearing/animating. That make sense? I've tried regular AS3 stuff like removing all children of my specified container clip + the container clip itself in the hope of taking the SWF with it, but this doesn't seem to do the trick - I think maybe i'm misunderstanding how the rawContent comes in? I'm just removing its parent ContentDisplay object and its, er, grandparent. Either way...doesn't do the job. Specifying queue.load(true) - to indicate I want the previous content unloaded and specified SWF loaded again (I think) - just gives me that blank/bg only SWF when I hit the button again.

 

This an AS2 problem? Would TweenLite fuelled AS3 content not have this problem? Am I just unloading wrong? Do I have to kill the tweens in the sub movie when I remove it? Any help would be MUCH appreciated. Thanks!

Link to comment
Share on other sites

I feel your pain. You stumbled across another bug in Flash that's very tricky to troubleshoot. I spent many hours tracking it down a week or two ago. It has to do with loading AS2 content into AS3 (well, AVM1 into AVM2) and then unloading it - Flash doesn't call onUnload() in the AS2 stuff and its _root reference inside the AS2 classes (like TweenLite) becomes invalid! Plus the onEnterFrame handlers stop working. Again, this is only a problem when you try loading an AS2-based swf into an AS3 parent swf and then unload it and load another AS2-based swf. And it's a bug in Flash, not TweenLite/Max or LoaderMax.

 

The way you can make sure your TweenLite stuff works in all your AS2 swfs is to use the latest version of TweenLite in them and call the new TweenLite.jumpStart(_root) method on the first frame. That will make sure that TweenLite has a valid _root reference which is necessary for the onEnterFrame stuff to work (which drives all the animations). Of course I'd strongly recommend just using a pure AS3-based workflow and don't load AS2 stuff unless you absolutely have to. AS3 is MUCH faster, better, and superior in virtually all ways. AS2 is a dying language so avoid it if you can.

Link to comment
Share on other sites

Aw...but I was so comfortable with AS2!! :D

Thing is, I know AS3 is the way forward and AS2 has had its day, but i'm still so much more comfortable with AS2....the more I learn in AS3, the more confusing I find it. I appreciate the elegance of the Object Orientated stuff, but I just find it alot harder to launch into, and the compiler seems alot more pedantic than the AS2 one. On the other hand, by strictly enforcing certain practices it can probably guarantee the improved performance, etc, etc. Yeah...i'll try and stick fully in the AS3 realm from now on. Slight problem is when i'm building bits for old websites (particularly old Content Management systems that have strange Flash implementation methods - sub loading clips forcing _lockroot and all the rest of it) and online ads for older ad serving networks...some haven't made the leap to AS3 yet.

 

Thanks for the assistance Jack...fantastic service and insight as usual. Often see you on these forums and in the FAQs going out of your way to point out a general Flash bug, NOT a Greensock one...you needn't bother! The amount of care and dedication you evidently pour in I don't think any one of us users would seriously think you've ever made a mistake and not Adobe!! I'll try that TweenLite.jumpStart(_root) thing later, but I think i'll just restrict myself to AS3 content...will save alot of headaches.

Link to comment
Share on other sites

Thanks for the assistance Jack...fantastic service and insight as usual. Often see you on these forums and in the FAQs going out of your way to point out a general Flash bug, NOT a Greensock one...you needn't bother! The amount of care and dedication you evidently pour in I don't think any one of us users would seriously think you've ever made a mistake and not Adobe!! I'll try that TweenLite.jumpStart(_root) thing later, but I think i'll just restrict myself to AS3 content...will save alot of headaches.

 

Ha ha. Well, I definitely make mistakes. There have indeed been bugs in my stuff before but I try very hard to get them patched within hours of discovering them, so they don't linger out there. I make a point to delineate responsibility ("this is not a bug in TweenLite/Max...") because some people get the wrong idea and might start to believe that GreenSock code is faulty and should be avoided even though the issue has nothing to do with GreenSock code. Well, that and I hate being wrong (just ask my wife) :)

 

Anyway, yeah, I think it's best that you learn AS3. I remember when I moved from AS2 to AS3. It was painful and confusing at first (sounds like where you are now) but over time you'll grow to love it. You'll never want to work in AS2 again once you get your bearings in AS3. Trust me. Force yourself to get over the learning curve and you'll be glad you did. Good luck.

Link to comment
Share on other sites

  • 4 weeks later...

I am building a project at the moment entirely in AS3 - but unfortunately I have to load one AS2 swf into it and have no option to convert as it is provided by a third party. I am using the loadermax swf loader successfully for all the swfs including the AS2 movie. However, when I call the dispose(true) method for the AS2 swf it doesn't work correctly and then breaks subsequent loads. Any help as to how to rectify would be fantastic. The loaded AS2 swf does not use any other greensock code.

 

Thanks in advance!

Link to comment
Share on other sites

Hmm....I just tested it with an AS2-based swf loading into an AS3-based on and everything worked perfectly. dispose(true) worked like a charm and it didn't cause any problems with other loaders. I wonder if there's something else going on in your project - could you please post a sample set of FLAs that can be published to easily see the problem? The simpler the better - no need to post your production files. I'm sure we can get if figured out once I see your files.

Link to comment
Share on other sites

Thanks for the response. I actually figured out what was going on.

 

Some of the files I was loading had video in them so before calling the dispose() method I was checking for the video & stopping as otherwise it continued to play the audio. When I attempted to do this on the AS2 swf it caused an error because script access was denied. This error then broke the other loader clicks.

 

So - I just wrote a check & only attempt to stop the video if script access is denied. Seemed to sort out the issue.

 

Thanks for a great class!

Link to comment
Share on other sites

  • 2 weeks later...

Hi there, another question about the dispose method and video.

 

I have a situation where a user can click to load external swfs that contain video. When the user clicks away from the current video to do something else I check for the video's exsistence, stop it from playing and then call the dispose method. I had to do it this was because when I called the dispose only I could still hear the video playing even though it did not exist on the stage.

 

Unfortunately, in testing my application I have discovered that if the user clicks away BEFORE the video has completely loaded this sequence fails. The user has moved on to a different section & then an invisible video begins to play in the background.

 

I thought that the dispose method should unload & destroy even if the raw content had not fully come down....?

 

Any help would be great.

Link to comment
Share on other sites

What are you calling dispose() on? The SWFLoader or the VideoLoader or both? Keep in mind that it would be absolutely impossible for SWFLoader to know about all the listeners, NetStreams, etc. that you've set up in the child swf and automatically clean up after you to make things eligible for garbage collection - you need to clean up after yourself in your child swf. It's considered a best practice to have a "dispose()" method (or whatever you want to name it) that removes any listeners you added, closes NetStreams, etc. You'd call that on your child swf before you dispose() the SWFLoader.

 

If, however, you're saying that you call dispose() on a VideoLoader and it still plays, please send me a sample that demonstrates the issue. I put a lot of effort into making sure all the loaders handle garbage collection very well (working around several Flash bugs in fact), so I'd be surprised to hear that dispose() isn't killing a VideoLoader properly, but maybe you hit a bug. Again, it'd be SUPER helpful to have a simple (please keep it simple) FLA that I can publish and see exactly what's going on.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×