一段精致的loading代码 |
| 作者:佚名 来源:不详 更新:2007-1-13 20:48:13 错误报告 我要投稿 |
|
全部AS完成。
MovieClip.prototype.loadhere=function(x,y,path,name){
//createsandpositionsclip,barandtext
varcontainerText=name+"text";
varcontainerBar=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;
//drawsthebar
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();
}
//loadsmovie
this[name].loadMovie(path);
varmovie=this[name];
varprelText=this[containerText];
varprelBar=this[containerBar];
//setsnewtextformat
varformtext=newTextFormat();
formtext.color="0x000000";
formtext.font="_sans";
formtext.align="center";
prelText.createTextField("loadtext",50,0,0,80,20);
prelText.loadtext.border=false;
//definestextdisplay
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){
deletethis.onEnterFrame;
this.removeMovieClip();
prelBar.removeMovieClip();
}
}
}
以上代码都在主场景第一桢。如要此代码工作该如何设置?举个例子:
比如你要load一个jpg(name:mm)或者一个swf(name:gg)
则可以在主场景中创建一个空MC(instancename:mc)(或者直接load进主场景)然后在桢1中加如下代码:
_root.mc.loadhere(0,0,"mm.jpg","mm");或者_root.mc.loadhere(0,0,"gg.swf","gg");
以后你若想LOADjip或者swf都可以直接使用上面的代码,你还可以改变进度条的颜色,大小等,很方便。需要指出的是,在本地无法观看效果。有空间的朋友可以试一试。
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |