• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS基础篇>Load相关>文章内容
  • 一段精致的loading代码
  • 来源:网络 作者:不详 2006-07-19 【
全部AS完成。

 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都可以直接使用上面的代码,你还可以改变进度条的颜色,大小等,很方便。需要指出的是,在本地无法观看效果。有空间的朋友可以试一试。




上一篇:LOADING制作方法   下一篇:详谈Loading[新手请看]
您的评论
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)