RTMPInvoker

by mezumona
Red5 とかでの接続テストとかに。
♥0 | Line 88 | Modified 2011-01-17 23:21:07 | MIT License
play

ActionScript3 source code

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

<?xml version="1.0" encoding="utf-8"?>

<s:Application
 xmlns:fx="http://ns.adobe.com/mxml/2009"
 xmlns:s="library://ns.adobe.com/flex/spark"
 xmlns:mx="library://ns.adobe.com/flex/halo"

 currentState="closed"
 >

    <fx:Declarations>
        
    </fx:Declarations>

    <s:layout>
        <s:VerticalLayout />
    </s:layout>

    <s:states>
        <s:State name="closed" />
        <s:State name="connecting" />
    </s:states>

    <s:Form width="100%" includeIn="closed">
        <s:FormItem label="uri" width="100%">
            <s:TextInput id="uriInput" width="100%" />
        </s:FormItem>
        <!--
        <s:FormItem label="connection params" width="100%">
            <s:TextInput id="conPramInput" width="100%" />
        </s:FormItem>
        -->
        <s:Button width="100%" label="connection!" click="invokeClickHandler(event);" />
    </s:Form>

    <s:Form includeIn="connecting">
        <s:FormItem label="command name">
            <s:TextInput id="commandNameInput" />
        </s:FormItem>
        <!--
        <s:FormItem label="command args">
            <s:TextInput id="commandArgsInput" />
        </s:FormItem>
        -->
        <s:Button width="100%" label="call!" click="callClickHandler(event);" />
        <s:Button width="100%" label="close." click="closeClickHandler(event);" />
    </s:Form>

    <s:TextArea id="messageArea" width="100%" height="100%">
    </s:TextArea>

    <fx:Script><![CDATA[
        import flash.net.NetConnection;
        import flash.events.NetStatusEvent;

        private var conn_:NetConnection;

        private function invokeClickHandler(event:MouseEvent):void
        {
            conn_ = new NetConnection();
            conn_.addEventListener(NetStatusEvent.NET_STATUS, connStatusEventHandler);
            conn_.connect(uriInput.text);
        }

        private function callClickHandler(event:MouseEvent):void
        {
            conn_.call(
                commandNameInput.text,
                new Responder(trace, trace)
            );
        }

        private function closeClickHandler(event:MouseEvent):void
        {
            conn_.removeEventListener(NetStatusEvent.NET_STATUS, connStatusEventHandler);
            conn_.close();
            conn_ = null;
            currentState = "closed";
        }

        private function connStatusEventHandler(event:NetStatusEvent):void
        {
            if (event && event.info) {
                switch (event.info.code) {
                    case "NetConnection.Connect.Closed":
                    case "NetConnection.Connect.Failed":
                    case "NetConnection.Connect.Reject":
                        trace(event.info.code);
                        currentState = "closed";
                        break;

                    case "NetConnection.Connect.Success":
                        currentState = "connecting";
                    default:
                        trace(event.info.code);
                }
            }
        }


        private function trace(...args):void
        {
            messageArea.appendText(args.join(" ") + "\n");
        }


    ]]></fx:Script>
</s:Application>