<< IPSEC Woes | Home | Does it make pfSense >>

Flash frozen on time

A recent bug tripped me up for a few hours, and so I thought it would be kind to share my embarrassing story. In my daily business, I use flash based rotators, a lot. If you ever took the time to stop by my official web site, you could see that I put a lot of value in flash as a content distribution system. So, it is a great concern, when one day I found an issue in one of my flash rotators. In the middle of rotating through a series of carefully selected images, one of them froze, in its place, dead on the screen. The tween itself never stopped, leaving me with a jumbled mess of images on top of each other peering out over the sides. PANIC!

This was of course discovered on a live site, so I quickly started searching through internet archives seeking advice on why an image would freeze mid tween. I found numerous examples of strange garbage collection issues that required global instantiation. Seeing that this fit my issue, I ran to the code to see how the variables were declared. The system was using two global variables, to cover the timeline of the tween (did I mention I inherited this particular section of code?). Anyway, it doesn't seem this is my problem.

What's worse is that I can't replicate it most of the time. It seems in order to make this happen, I have to travel to my local *bucks (this is actually important), sacrifice a chicken, and drink a latte. So I continue scouring the internet -- tons of articles about the garbage collection. Many of them a very interesting read. If you are ever distributing a lot of content via flash, look up flash garbage collection. I even switched out to a few tween libraries hoping one of them would fix what I could only guess might be a bug in flash.

Of course, that wasn't helping, so in a desperate slump I began reading various flash forums, until one mention caught my eye. An off-handed remark about not loosing the reference to the image variable while in the tween. I of course had been focusing on what was happening to the tween, so I never noticed that in the call back function for changing slides, it was always assumed that ImageA variable was not in the middle of a tween operation. So when the call back hit the following line:

ImageA = new Loader();

flash dropped the image right where it was and moved on with its life. The fix, simple placing the following code at the begining:

if (ImageA != null && contains (ImageA) ) {
    removeChild ( ImageA);
}

Oh, and why the *bucks was relevant. The bug only occured when the images loaded so slowly that the next image was still loading when the tween for the first finished. Decent code, silly mistake, bad day. Hope this entry finds it's way to someone in need of a solution.
 




Add a comment Send a TrackBack