Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created September 2, 2010 18:57
Show Gist options
  • Save kara-ryli/562746 to your computer and use it in GitHub Desktop.
Save kara-ryli/562746 to your computer and use it in GitHub Desktop.
This document class avoids some initialization problems I've encountered in IE when Flash is loaded from cache
package {
import flash.display.MovieClip;
import flash.events.Event;
/**
* Sometimes, when the SWF is pulled from cache, the first frame is
* is played before the Flash player is actually initialized. Many
* functions do not yet exist at this point. In addition, stage.stageWidth
* is zero. Within a few milliseconds everything is ready.
*/
public class AvoidIECacheProblems extends MovieClip {
public function AvoidIECacheProblems() {
this.addEventListener(Event.ENTER_FRAME, onFirstFrame, false, 0, true);
}
private function onFirstFrame(event:Event):void {
if (this.stage.stageWidth) {
this.removeEventListener(Event.ENTER_FRAME, onFirstFrame, false);
this.initialize();
}
}
protected function initialize():void {
// this is where the magic happens
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment