Flash as3.0 load SWF failure resolution

Source: Internet
Author: User
Tags addchild

Flash as3.0 load SWF code how to write? If there are 1.swf, with 2.fla load, in 2.FLA code how to write

Add: There is already a paragraph in 2.fla, load 1.swf is want to finish 2.FLA before the first paragraph after the 2.swf. So the code is written to the last frame of the 2.FLA itself.

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);
}


Here's a paragraph written in class open loaded SwF method

var name_array:array=["swf/a.swf", "swf/b.swf", "swf/c.swf", "swf/d.swf"];//save an array of SWF names
var p:uint =new uint;//Remember that the first few SWF in the array are currently playing (the pointer starts at 0)
var play_mc:movieclip =new movieclip;//the currently playing 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;
---------------------Binary load 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);
}
------------------------Load Completed------------------------
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);
}
-----------------------detect whether to play to the last frame---------------
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 = "Current playback is:" +name_array[p]+ "(" +_mc.currentframe + "/" +_mc.totalframes + ")";
}
------------------------Detect button Events-----------------------
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);
----------------------The first SWF is loaded by default-------------------
Swfload ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.