MovieClip.prototype.loadhere=function(x,y,path,name) {
// creates and positions clip, bar and text
var containerText=name+"text";
var containerBar=name+"bar";
this.createEmptyMovieClip(name,1);
this.createEmptyMovieClip(containerText,2);
this.createEmptyMovieClip(containerBar,3);
this[name]._x=x;
this[name]._y=y;
this[containerText]._x=x;
this[containerText]._y=y;
this[containerBar]._x=x;
this[containerBar]._y=y;
// draws the bar
with (this[containerBar]){
beginFill (0xDDDDDD, 50);
lineStyle (1, 0x000000, 100);
moveTo (0, 0);
lineTo (80, 0);
lineTo (80, 20);
lineTo (0, 20);
lineTo (0,0);
endFill();
}
// loads movie
this[name].loadMovie(path);
var movie=this[name];
var prelText=this[containerText];
var prelBar=this[containerBar];
// sets new text format
var formtext=new TextFormat();
formtext.color="0x000000";
formtext.font="_sans";
formtext.align="center";
prelText.createTextField("loadtext",50,0,0,80,20);
prelText.loadtext.border=false;
// defines text display
prelText.onEnterFrame=function() {
if(this.percent!=100) {
this.percent=int((movie.getBytesLoaded()/movie.getBytesTotal())*100)
this.loadtext.text="Loading "+this.percent+"%";
this.loadtext.setTextFormat(formtext);
prelBar._xscale=this.percent;
}
if(this.percent==100) {
delete this.onEnterFrame;
this.removeMovieClip();
prelBar.removeMovieClip();
}
}
}
以上代码都在主场景第一桢。如要此代码工作该如何设置?举个例子:
比如你要load一个jpg(name:mm)或者一个swf(name:gg)
则可以在主场景中创建一个空MC(instance name:mc)(或者直接load进主场景)然后在桢1中加如下代码:
_root.mc.loadhere(0,0,"mm.jpg","mm");或者_root.mc.loadhere(0,0,"gg.swf","gg");
以后你若想LOAD jip 或者swf都可以直接使用上面的代码,你还可以改变进度条的颜色,大小等,很方便。需要指出的是,在本地无法观看效果。有空间的朋友可以试一试。
Flash 动画: