Suspended animation
February 8th, 2009
Recently, I've been working on a project with some unorthodox requirements; the flash piece in question needed to be removed from the page and brought back later without losing its state or reloading its external assets. To that end I knocked together a loop which removes everything from the stage and stores it to an array for later. Once clear, the swf is then throttled down to the minimum framerate.
In hibernation, the swf has nothing to render (which takes care of enterFrames, mouseEvents, etc.) and the stage refreshes are pushed out to one every 100 seconds, so cpu use is essentially nil, while all the swf assets chill out in memory until I want them again.
While I was working on the code to reanimate, I got to thinking about the elastic racetrack and it occurred to me that throttling the framerate down to under a second may be problematic – luckily the ExternalInterface (which I so love to hate) already supplied the answer. Since external callbacks are synchronous, they interrupt the normal progression of the code, so it's possible to reset the framefrate without waiting for the next frame to fire.
