Created
September 2, 2010 18:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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