注:本代码参考网上的loading代码,出处本人未知
本人仅修改并测试使得其使用于任何一个loading调用

function show_loading(loader) {
 var myLoading:MovieClip;
 var loadInfo:MovieClip;
 var _lineBgcolor = "0x666666";
 var _lineColor = "0x0000FF";
 var _lineLen:Number = 200;
 var _lineH:Number = 3;
 var _txtColor;
 var _txtAlign:String = "center";
 var tb:Number;
 var txtFormat:TextFormat = new TextFormat("Arial", null, 0x000000, true);
 //建立一个最高层做loading
 myLoading = _root.createEmptyMovieClip("myLoading", _root.getNextHighestDepth());
 //描绘进度条
 loadInfo = myLoading.createEmptyMovieClip("line", 10);
 loadInfo.lineStyle(1, _lineColor, 20);
 loadInfo.moveTo(0, 0);
 loadInfo.lineTo(_lineLen, 0);
 loadInfo.lineTo(_lineLen, _lineH);
 loadInfo.lineTo(0, _lineH);
 loadInfo.lineTo(0, 0);
 //进度显示文本 , 设置进度条的位置(居中于主场景)
 loadInfo.createTextField("txt", 30, 0, 0, _lineLen, 22);
 loadInfo.txt.autoSize = _txtAlign;
 loadInfo._x = (Stage.width-_lineLen)/2;
 loadInfo._y = Stage.height/2;
 //获得影片大小并stop,再onEnterFrame
 loader.stop();
 tb = loader.getBytesTotal();
 //trace("tb:"+tb);
 myLoading.onEnterFrame = function() {
  if (tb<=0) {
   //有时候会在上面得到tb为0,需要判断一下
   tb = loader.getBytesTotal();
   //trace("tb:"+tb);
  }
  var lb:Number = loader.getBytesLoaded();
  var percent:Number = Math.round(lb/tb*100);
  //trace("lb:"+lb+" / tb:"+tb);
  loadInfo.txt.text = percent+"%";
  loadInfo.txt.setTextFormat(txtFormat);
  loadInfo.lineStyle(_lineH, _lineBgcolor, 10);
  loadInfo.moveTo(0, _lineH/2);
  loadInfo.lineTo(percent*_lineLen/100, _lineH/2);
  if (percent == 100) {
   loader.play();
   delete this.onEnterFrame;
   this.removeMovieClip();
   //把本层loading删除
  }
 };
}

用法:

在第一帧
show_loading(_root);

或者:
b_mc.loadMovie("3.jpg");
show_loading(b_mc);




原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
发表评论
AD
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐