เริ่มเกิดอาการเครียดเพราะท่าทางจะทำ project ไม่เสร็จ
เข้ามาคุ้ยกระจู๋ อยู่หลายวันก็ไม่เจอสิ่งที่ต้องการ เลยดำน้ำเอง
สุดท้ายก็ประสพผลสำเร็จ...
function loadClip(mc){
var mcl:MovieClipLoader = new MovieClipLoader();
var mclL:Object = new Object();
_root.createEmptyMovieClip("holder",_root.getNextHighestDepth());
var rect:MovieClip = createRectangle(200, 20, 0x003366, "bar");
centerObj(bar);
var rect:MovieClip = createTextField("Ltext",getNextHighestDepth(),0,0,200,40);
Ltext.type = "StaticText" ;
centerObj(Ltext);
Ltext._y-=10;
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0x000000;
my_fmt.align = "center" ;
my_fmt.size=18;
Ltext.setTextFormat(my_fmt);
centerObj(loadTXT);
mclL.onLoadProgress = function(target,loaded,totled){
trace("loading to "+target+" - "+loaded+" of "+totled +" "+Math.round((loaded/totled) * 100) +" % ");
loadTXT.text = Math.round((loaded/totled) * 100)+"%";
holder._visible=false;
bar._xscale=Math.floor(100*getBytesLoaded()/getBytesTotal());
Ltext.text=bar._xscale+" % ";
Ltext.setTextFormat(my_fmt);
}
mclL.onLoadInit = function(){
trace("done");
Ltext.text = "Del";
removeMovieClip(Ltext);
Ltext.unloadMovie();
removeMovieClip(bar);
bar.unloadMovie();
holder._visible=true;
holder._x=0;
holder._y=0;
}
mcl.addListener(mclL);
mcl.loadClip(mc,holder);
}
function centerObj(obj){
var scrWidth=800;
var scrHeight=600;
obj._x=(scrWidth/2)-((obj._width)/2);
obj._y=(scrHeight/2)-((obj._height)/2);
}
อันนี้อาศัยเขียนเองบวกกับเอานู่นนิดนี่หน่อยมารวมๆกัน
ที่เอามา แปะไว้นี่เพราะว่า หลังจากลองใช้แล้วคิดว่าเป็นประโยชน์
วิธีใช้งาน
สร้าง file.as มาหนึ่ง file สมมุติว่าชื่อ "load.as"
เอา code ด้านบนไปใส่แล้วไปที่งานหลัก(หน้าที่จะโหลดหน้าอื่น)
พิมพ์
#include "load.as"//ที่อยู่ของ file .as
loadClip("movieClip.swf");// ที่อยู่ของFileที่จะโหลดเข้ามา
ปล. การโหลดอันนี้เป็นการโหลดลง EmptyMovieClip เพราะฉนั้น จะไม่ไปทับ _root

แล้วเดียวจะมาอธิบาย code นะครับ ขอตัวไปทำ Project ก่อน
