第一种:在显示加载进度,而且可以用来加载 图片或其它swf文档。使用方法
1,把以下代码放在第一帧
2,建立一个空的影片剪辑,放到第一帧,并起名字mc(可以随便起,使用名字引用这个影片剪辑,做为加载的容器使用)
3,加载jpg图片的话,则加 _root.mc.loadhere(0,0,"mm.jpg","mm")代码 0,0是图片加载的位置,mm.jpg是图片文件名和路径
4,加载swf文件则使用以下代码:_root.mc.loadhere(0,0,"gg.swf","gg") 含义与图片相同
代码如下:
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();
}
}
}
第二种:矩形框显示进度,只要放在第一帧就可以了,你也可以调整位置。即rect1 rect2的_x _y的值
stop();
var rect1:MovieClip = createRectangle1(150, 3, 0x000000);
var rect2:MovieClip = createRectangle2(152, 5, 0x000000);
rect1._x = (Stage.width - rect1._width) / 2;
rect1._y = (Stage.height - rect1._height) / 2;
rect2._x = (Stage.width - rect2._width) / 2;
rect2._y = (Stage.height - rect2._height) / 2;
onEnterFrame = function () {
rect1._width = _root.getBytesLoaded() / _root.getBytesTotal() * 150;
if (_root.getBytesLoaded() == _root.getBytesTotal()) {
rect1.removeMovieClip();
rect2.removeMovieClip();
delete rect1;
delete rect2;
delete createRectangle1;
delete createRectangle2;
delete onEnterFrame;
play();
}
};
function createRectangle1(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
scope = (scope == undefined) ? this : scope;
var depth:Number = scope.getNextHighestDepth();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
mc.beginFill(color);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);
return mc;
}
function createRectangle2(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
scope = (scope == undefined) ? this : scope;
var depth:Number = scope.getNextHighestDepth();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
mc.lineStyle(color);
mc.moveTo(0, 0);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);
return mc;
}