topical media & game development

talk show tell print

professional-flex-code-08-ExternalInterfaceSample.mx

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


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
          creationComplete="initApp()" backgroundColor="#FFFFFF"
          width="400" height="250">
    <mx:Script>
    import flash.external.ExternalInterface;
    import mx.controls.Alert;
    public function initApp():void {
      this.setupCallbacks();
    }
    // Called from Javascript
    public function callFromJavascript(s:String):void {
      Alert.show(s,"Flex Alert");
    }
    // Call to Javascript
    private function sendToJavaScript():void {
      ExternalInterface.call("getFromFlex",valueForJavascript.text); 
    }
    // Setup Callbacks
    private function setupCallbacks():void{
            ExternalInterface.addCallback("callFromJavascript",callFromJavascript);
    }
    </mx:Script>
    <mx:Panel title="ExternalInterface Sample" width="350" height="200">
      <mx:HBox>
        <mx:TextInput id="valueForJavascript" text="Hello From Flex" />
        <mx:Button click="this.sendToJavaScript()" label="Send to Javascript" />
      </mx:HBox>
    </mx:Panel>
  </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.