buttonMode=true prevent swf to unload

Wow I just spent 3 days debugging my app to find out that an unloading SWF problem I had, it wasn’t my fault but an Adobe Flash Player bug…… and a weird one!

here is the blog that saved my time:

Combine buttonMode = true and a mouse click to leak memory

it looks like that if you set

buttonMode = true

of a Sprite,  and then the user interacts with that Sprite, the SWF file container once loaded cannot be unloaded.
(here is the bug report where adobe set it as “NOT A BUG”!)

This happens with Flash Player 9, so then, after reading Grant Skinner’s blog about the new unloadAndStop method in the Loader class available for Flash Player 10 and after feeling full of hope I changed my code to use it to unload my loaded SWF but nothing, the bug is still there.

I know that most people won’t use the buttonMode = true as they can use the SimpleButton class, but sometimes for speed and testing it’s easier to just set that property to have a Sprite to act as a button.

So be aware of this problem and I hope Adobe will fix it soon or deprecate the buttonMode property.

This entry was posted in AS3, Flash. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Vizio: removing objects in AS3 is a pain in the ass. Every reference (event listener, variable, mask etc) can prevent an object for being garbage collected. Even it's very annoying, it's just the way Flash works.

    That's why I created my own library for handling object destruction. I does everything that Flash should do when you want to remove an object, like removing event listeners, clear focus, remove masks etc. It's open-source, so you can try it out for yourself: http://code.google.com/p/templelibrary/
    This will help to fix your problem.

    BTW: I didn't receive the example. Did you mail it?
  • vizio360
    Hi Thijs,

    yeap it is a pain :) and so why don't ask Adobe to improve it by reporting bugs?

    btw I did send you a pull request from GitHub maybe I got the email wrong, so here it is:

    http://github.com/vizio360/buttonModeTrueBug
  • Vizio: Like you've sad, it's because you have clicked on the button. If you click on an object it will be set in the stage.focus. That will prevent it for being removed by the garbage collector.

    But if you press on something else, the stage.focus will be set on the other object and your button can be removed by the garbage collector.

    So this has nothing to do with the buttonmode property and it's definitely not a bug.
  • vizio360
    Hi Thijs,

    mmm I don't see your point, the thing is that even if the user clicks on the button when I decide to unload the swf it should unload it properly, so the flash player should automatically reset the stage.focus property.

    Btw if you see in the example I sent you, you'll see a line to set of the stage.focus to null commented out, just remove the comment and run it again. Even if you do that the swf doesn't unload.

    Are there any other ways to reset the stage.focus property?
  • Hi, I tried this one. But in my test everything works correctly. The object with button mode enabled can be unloaded and removed from memory.

    So can you put your test files online so I can check them out?
  • vizio360
    Hi Thijs,

    yeap sure, as soon as I get home I'll put them on line.

    btw in your tests do you press the button with the mouse before unloading the swf file?

    The problem appears only if you click on the button and then you try to unload the swf.

    I also did have an update on it that I never tried. The thing was to set the focus property of the button to null before unloading the swf. It looks like that if you set the buttonMode to true and then you interact with the button the flash focus manager will set the focus property of the button to stage and that prevents the swf to unload. Unfortunately I haven't testes it yet.
  • vizio360
    Hi Philippe, I'm not sure I get your question. My blog is more of a bug report instead of a solution for a problem.
  • Philippe
    Does it fix the bug to set buttonMode to false when removing the element from stage?
blog comments powered by Disqus