In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Red5を導入してみる - 1. サーバに接続

FMSのデベロッパー版を導入していじってみたいのにMac版はない...!?
と思って色々探していたら,Macでも利用できる"Red5"というオープンソースFlashサーバを発見.
今回はとりあえず接続できるかテスト.
(要Red5インストール)


Red5:http://osflash.org/red5
参考URL:http://thinkit.co.jp/article/152/3
Get Adobe Flash player
by geko 23 Nov 2010
    Embed
/**
 * Copyright geko ( http://wonderfl.net/user/geko )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zvfV
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.events.NetStatusEvent;
    
    public class FlashTest extends Sprite {
        public var txt:TextField;
        public var server:Red5;
        
        public function FlashTest() {
            txt = addChild(new TextField()) as TextField;
            txt.width = stage.stageWidth;
            txt.height = stage.stageHeight;
            
            server = new Red5();
            server.connect("rtmp://localhost/test");
            server.addEventListener(NetStatusEvent.NET_STATUS, function netStatus(event:NetStatusEvent):void{
                trace(event.info.code);
            });
        }
        
        public function trace(...str):void{
            txt.appendText("\n");
            txt.appendText(str.toString());
            txt.scrollV = txt.maxScrollV;
        }

    }
}

import flash.events.EventDispatcher;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;

class Red5 extends EventDispatcher{
    public var nc:NetConnection;
    public function Red5():void{
        nc = new NetConnection();
        nc.addEventListener(NetStatusEvent.NET_STATUS, function _dispatchEvent(event:NetStatusEvent):void{
            dispatchEvent(event);
        });
    }
    public function connect(serverURL:String):void{
        nc.connect(serverURL);
    }
}