import mx.controls.Alert; import flash.external.ExternalInterface; private function initApp():void{ if(this.isJSReady()){ // JavaScript ready so we can setup the call backs from JavaScript this.setupCallbacks(); } else { // create a timer to poll JavaScript until it is ready var readyTimer:Timer = new Timer(100); readyTimer.addEventListener(TimerEvent.TIMER, jsNotReady); readyTimer.start(); } } private function isJSReady():Boolean { // Call to JavaScript to see if it is ready return ExternalInterface.call("isJSReady");; } private function jsNotReady(event:TimerEvent):void { // Check to see if JavaScript is ready and stop timer if it is if (this.isJSReady()) { Timer(event.target).stop(); // JavaScript ready so we can setup the call backs from JavaScript this.setupCallbacks(); } } private function setupCallbacks():void{ // Add Callbacks here mx.controls.Alert.show("JavaScript is Ready"); }