Log In  
  Getting Started  
----------------------------------------

Resources

 

External Interface

The ExternalInterface class enables  communication between ActionScript and Flash Player containers such as an HTML page containing JavaScript and an embedded SWF file, or an application that has the Flash Player embedded in it. The communication is available in both directions. An HTTP/JavaScript page can call an ActionScript function which can return data that the JavaScript can use or ActionScript can call Javascript.

ActionScript can call any JavaScript function passing arguments and receiving a return value from the JavaScript function.  JavaScript on the HTML page can easily call an ActionScript function complete with arguments and return values. 

previous page next page

User rating?

Main.MXML

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="initConn()"
    backgroundAlpha="0" backgroundColor="#FFFFFF">
     <mx:Script>
        <![CDATA[
            import flash.net.LocalConnection;

            private var conn:LocalConnection;

            private function initConn():void{
                btnSend.addEventListener(MouseEvent.CLICK, sendMessage);
                conn = new LocalConnection();
                conn.addEventListener(StatusEvent.STATUS, onStatus);
            }

            private function sendMessage(event:MouseEvent):void {
                conn.send("taskConnection", "localconnectionHandler", inputTask.text);
            }

            private function onStatus(event:StatusEvent):void {
                switch (event.level) {
                    case "status":
                        ExternalInterface.call("showStatus", "Task successfully sent");
                        break;
                    case "error":
                        ExternalInterface.call("showStatus", "Task failed to send");
                        break;
                }
            }

        ]]>
    </mx:Script>
    <mx:Panel horizontalCenter="0" verticalCenter="0">
        <mx:Form width="100%" height="100%" horizontalCenter="0" verticalCenter="0">
            <mx:FormItem label="Enter Task">
                <mx:TextInput id="inputTask"/>
            </mx:FormItem>
            <mx:FormItem label="Send Task ">
                <mx:Button id="btnSend" label="Send"/>
            </mx:FormItem>
            <mx:ControlBar>
                <mx:Label id="labelStatus" text=""/>
            </mx:ControlBar>
        </mx:Form>
    </mx:Panel>
</mx:Application>
previous page next page
Added by Mark Nichoson , last edited by Randy Nielsen on Feb 22, 2008  (view change)
Labels: 
(None)

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators