Si può usare la classe Video in collaborazione con NetStream e NetConnection.
Il codice è un po' ridondante perchè sono necessari diversi controlli per verificare la connessione di NetConnection, il caricamento in streaming del file e il termine dell'esecuzione dello stesso.
Se sei abbastanza ferrato su AS3, non dovresti trovare difficoltà a leggere e interpretare il codice seguente:
Codice PHP:
stop ();
var v:Video, c:NetConnection, s:NetStream;
v = addChild(new Video(550,400)) as Video;
c = new NetConnection();
c.addEventListener (NetStatusEvent.NET_STATUS, netStatus);
c.addEventListener (SecurityErrorEvent.SECURITY_ERROR, function (e:SecurityErrorEvent){});
function netStatus (e:NetStatusEvent) {
switch (e.info.code) {
case "NetConnection.Connect.Success" :
playVideoStream ();
break;
case "NetStream.Play.Stop" :
stopVideoStream ();
break;
case "NetStream.Play.StreamNotFound" :
videoStreamNotFound ();
break;
}
}
function playVideoStream () {
s = new NetStream(c);
s.addEventListener (NetStatusEvent.NET_STATUS, netStatus);
s.addEventListener (AsyncErrorEvent.ASYNC_ERROR, function (e:AsyncErrorEvent) {});
v.attachNetStream (s);
v.smoothing = true;
s.play ("test_video.flv");
}
function stopVideoStream () {
v.attachNetStream (null);
v.parent.removeChild (v);
play ();
}
function videoStreamNotFound () {
trace ("Unable to locate video");
}
c.connect (null);