flash as3.0加载swf失败解决方法

作者:袖梨 2022-06-28

flash as3.0加载swf代码怎么写?如已有1.swf,用2.fla加载,在2.fla里的代码怎么写

补充:2.fla里已有一段,加载1.swf是想放完2.fla前一段后接着放2.swf的。所以代码是要写到2.fla本身的最后一帧的吧

 

var my_urlloader:loader=new loader();
my_urlloader.load(new urlrequest("swf.swf"));
my_urlloader.contentloaderinfo.addeventlistener(event.complete,_show);
function _show(e:event):void {
addchild(my_urlloader);
}


下面来一段写成了类开加载swf方法

var name_array:array=["swf/a.swf","swf/b.swf","swf/c.swf","swf/d.swf"];//保存swf名的数组
var p:uint =new uint;//记住当前播放的是数组中的第几个swf(指针从0开始)
var play_mc:movieclip =new movieclip;//当前播放的swf
//--------------------------------------------------------
addchild(play_mc);
var swf_loader:loader=new loader;
var swf_urlloader:urlloader =new urlloader;
var swf_urlrequest:urlrequest =new urlrequest;
swf_urlloader.dataformat =urlloaderdataformat.binary ;
//---------------------二进制加载swf-------------------------
function swfload() {
        p=p<0?(name_array.length -1):p%=name_array.length ;
        try {
                swf_urlrequest.url =name_array[p];
                swf_urlloader.load(swf_urlrequest);
                swf_urlloader.addeventlistener(event.complete ,binaryloadcomplete);
        } catch (_err:error) {
                trace(_err);
        }
}
function binaryloadcomplete(_evt:event):void {
        //swf_loader=new loader;
       
        swf_loader.loadbytes(_evt.target.data);
        swf_loader.contentloaderinfo.addeventlistener(event.complete ,swfloadcomplete);
}
//------------------------加载完成------------------------
function swfloadcomplete(_evt:event):void {
        removechild(play_mc);
        play_mc=_evt.target.loader.content as movieclip;
        play_mc.addeventlistener(event.enter_frame,onmcenterframe);
        swf_loader.unload ();
        addchild(play_mc);
}
//-----------------------检测是否播放到最后一帧---------------
function onmcenterframe(_evt:event):void {
        var _mc:movieclip=_evt.target as movieclip;
        if (_mc.currentframe ==_mc.totalframes ) {
                _mc.removeeventlistener(event.enter_frame,onmcenterframe);
                p++;
                swfload();
        }
        info_txt.text ="当前播放的是:"+name_array[p]+"  ( "+_mc.currentframe +"/"+_mc.totalframes +")";
}
//------------------------检测按钮事件 -----------------------
function onbtnclick(_evt:mouseevent):void {
        var _btn:button =_evt.target as button;
        switch (_btn) {
                case prev_btn :
                        p--;
                        break;
                case next_btn :
                        p++;
                        break;
        }
        swfload();
}
prev_btn.addeventlistener(mouseevent.click ,onbtnclick);
next_btn.addeventlistener(mouseevent.click ,onbtnclick);
//----------------------默认加载第一个swf-------------------
swfload();

相关文章

精彩推荐