Flex+FMS最简单的例子
- 06月 15th, 2008
-
MXML:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.controls.Alert; public var netConnection:NetConnection; public var myVideo:Video; public var netStream:NetStream = null; public function init():void{ netConnection = new NetConnection(); // netConnection.objectEncoding = ObjectEncoding.AMF0; netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); netConnection.connect("rtmp:/Flv"); } private function netStatusHandler(event:NetStatusEvent):void{ switch (event.info.code){ case "NetConnection.Connect.Failed": break; case "NetConnection.Connect.Success": initMedia(); break; case "NetStream.Play.StreamNotFound": break; } } private function securityErrorHandler(event:SecurityErrorEvent):void{ //Alert.show("securityErrorHandler: " + event); } private function initMedia():void{ netStream = new NetStream(netConnection); netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,streamErrorHandler); myVideo = new Video(); myVideo.attachNetStream(netStream); myVideo.width = 400; myVideo.height = 400; netStream.play("test"); mx_Vd.addChild(myVideo); } private function streamErrorHandler(event:AsyncErrorEvent):void{ //Alert.show(event.error.message); } public function replay():void{ netConnection.close(); myVideo.attachCamera(null); myVideo.clear(); init(); } ]]> </mx:Script> <mx:VideoDisplay id=”mx_Vd” width=”400″ height=”400″ creationComplete=”init();”> </mx:VideoDisplay> <mx:Button label=”Replay” click=”replay();”/> </mx:Application>在
FSM安装目录\applications\Flv\streams\_definst_
下拷贝一个phone.flv