onPlayStatus as3
New to this one. Have this code for viewing multiple netstream events. Want to use the onPlayStatus to loop the "flv/intro.flv" and for the rest of the videos, I would like them to return to the intro.flv after they are done playing, but I can't find anything that helps enough. Can anyone offer a link or some help with the function? Here is my code so far :
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var metaDataListener:Object = new Object();
metaDataListener.onMetaData = function(meta:Object){
}
ns.client = metaDataListener
var myVideo:Video = new Video(800, 600);
myVideo.x = 0;
myVideo.y = 0;
addChild(myVideo);
setChildIndex(myVideo, 0);
myVideo.attachNetStream(ns);
ns.play("flv/intro.flv");
duetBTN.addEventListener(MouseEvent.CLICK, playVideo1);
vantageBTN.addEventListener(MouseEvent.CLICK, playVideo2);
cabrioBTN.addEventListener(MouseEvent.CLICK, playVideo3);
classicBTN.addEventListener(MouseEvent.CLICK, playVideo4);
laundryBTN.addEventListener(MouseEvent.CLICK, playVideo5);
resourceBTN.addEventListener(Mou开发者_如何学JAVAseEvent.CLICK, playVideo6);
industryBTN.addEventListener(MouseEvent.CLICK, playVideo7);
homeBTN.addEventListener(MouseEvent.CLICK, playVideo8);
function playVideo1(e:MouseEvent):void {
ns.play ("flv/duet.flv");
}
function playVideo2(e:MouseEvent):void {
ns.play("flv/vantage.flv");
}
function playVideo3(e:MouseEvent):void {
ns.play("flv/cabrio.flv");
}
function playVideo4(e:MouseEvent):void {
ns.play("flv/classic.flv");
}
function playVideo5(e:MouseEvent):void {
ns.play("flv/laundry.flv");
}
function playVideo6(e:MouseEvent):void {
ns.play("flv/resource.flv");
}
function playVideo7(e:MouseEvent):void {
ns.play("flv/industry.flv");
}
function playVideo8(e:MouseEvent):void {
ns.play ("flv/intro.flv");
}
You can attach an event listener to the NetStream object that detects when a video has finished playing.
var introPlayer:NetStream = new NetStream(nc); // nc refers to shared net connection declared earlier
var introVid:Video = new Video(800, 600);
ns.addEventListener(NetStatusEvent.NET_STATUS, checkStreamStatus);
function checkStreamStatus(e:NetStatusEvent):void {
switch (e.info.code) {
case "NetStream.Play.Complete":
playIntro();
break;
}
};
function playIntro():void {
addChild(introVid);
introVid.attachNetStream(introPlayer);
introPlayer.play("flv/intro.flv");
}
Have changed the code completely to match the set-up you were using originally. This is how you're supposed to do it, apologies for previous answer. This is the correct way of doing it though.
If NetStream.Play.Complete
is not dispatched, replace it with:
NetStream.Play.Stop
or NetStream.Buffer.Flush
精彩评论