How to load swf file with event handlers in AS3?
stop();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var listener:Object = new Object();
liste开发者_运维问答ner.onMetaData = function(md:Object):void{};
listener.onPlayStatus = function(info : Object) : void {
trace("onPlayStatus:" +info.code + " " + info.duration);
if (info.code == "NetStream.Play.Complete") {
var endLoader:Loader = new Loader();
endLoader.load(new URLRequest("secondmovie.swf"));
addChild(endLoader);
initializeVideo();
}
};
ns.client = listener;
vid1.attachNetStream(ns);
var movietoplay:String = "firstmovie.flv";
ns.play(movietoplay);
function initializeVideo():void {
ns.close();
}
Can anyone help me load the swf once the flv is done playing? I think I'm just not loading the swf right because the flv plays correctly.
The swf should already be loaded when the video complete event fires, this way it would start playing instantly as opposed to waiting for it to load , then play. simply preload the swf and when the video finishes , add the swf to the display list.
at the moment you wait for the video to complete to start loading , not playing the swf , meaning that there will be a delay proportional to the swf size , before it starts playing
stop(); //start the swf loading process var endLoader:Loader = new Loader(); endLoader.load(new URLRequest("secondmovie.swf")); //start the video var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); var listener:Object = new Object(); listener.onMetaData = function(md:Object):void{}; listener.onPlayStatus = function(info : Object) : void { trace("onPlayStatus:" +info.code + " " + info.duration); if (info.code == "NetStream.Play.Complete") { //unless the swf size is really big or the video really short , //the swf should be loaded //add it it should start playing straight away. addChild(endLoader); initializeVideo(); } }; ns.client = listener; vid1.attachNetStream(ns); var movietoplay:String = "firstmovie.flv"; ns.play(movietoplay); function initializeVideo():void { ns.close(); }
精彩评论