topical media & game development

talk show tell print

professional-flex-code-08-ExternalInterfaceJSTest.mx

professional-flex-code-08-ExternalInterfaceJSTest.mx [swf] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
          backgroundColor="#FFFFFF" creationComplete="initApp();"
          width="350" height="300">
    <mx:Script>
    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");
    }
    </mx:Script>
  </mx:Application>
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.