forked from: kamaitachi example echo

by mash forked from kamaitachi example echo (diff: 1)
♥1 | Line 43 | Modified 2010-10-18 10:37:06 | MIT License
play

ActionScript3 source code

/**
 * Copyright mash ( http://wonderfl.net/user/mash )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2jNC
 */

<?xml version="1.0"?>
<!-- forked from typester's kamaitachi example echo -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
    <mx:Script><![CDATA[
import flash.net.*;
import flash.events.*;

private var nc:NetConnection;

private function init():void {
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
    nc.objectEncoding = ObjectEncoding.AMF0;
    nc.connect("rtmp://127.0.0.1/rpc/echo");
}

private function status_handler(event:NetStatusEvent):void {
    switch (event.info.code) {
    case "NetConnection.Connect.Success":
        setStatus("connected.");
        break;
    default:
        setStatus(event.info.code);
    }
}

private function setStatus(text:String):void {
    status.text = text;
}

private function callEcho():void {
    if (!input.text) return;

    nc.call("echo", new Responder(callEchoResponse), input.text);
    input.text = "";
}

private function callEchoResponse(res:String):void {
    result.text = res + "\n" + result.text;
}

    ]]></mx:Script>
    <mx:Panel title="echo remoting sample" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
        <mx:HBox>
            <mx:TextInput id="input" width="120"/>
            <mx:Button label="echo" click="callEcho()"/>
        </mx:HBox>
        <mx:TextArea id="result" width="300" height="100" text=""/>
        <mx:Label id="status" text="Connecting..."/>
    </mx:Panel>
</mx:Application>