示例
package {
import flash.events.NetStatusEvent;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.events.Event;
import flash.media.Video;
import flash.display.Sprite;
public class VideoWithNetStatus extends Sprite {
private var video:Video = new Video();
private var nc:NetConnection;
private var ns:NetStream;
public function VideoWithNetStatus() {
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
nc.connect(null);//或媒体服务器网址
}
private function onStatus(e:NetStatusEvent):void{
switch(e.info.code){
case 'NetConnection.Connect.Success':
connectStream();
break;
default:
trace(e.info.code);//看到任何未发生的事件
}
}
private function connectStream():void{
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
addChild(video);
video.attachNetStream(ns);
ns.play('url/to/video.flv');
}
}
}