简体   繁体   English

Flash Preloader as3

[英]Flash Preloader as3

Is it possible to set total bytes in an as3 preloader? 是否可以在as3预加载器中设置总字节数? I'm not sure it's correct, but to avoid an infinite loop I've done this. 我不确定这是正确的,但是为了避免无限循环,我这样做了。

var loadper:Number=0;
var total_bytes:Number = 3484484;
loaderInfo.addEventListener(ProgressEvent.PROGRESS, loader);

function loader(filename:ProgressEvent) { 
   var loaded_bytes:Number = stage.loaderInfo.bytesLoaded;
   _txt.text=String(loadper+"%");
   if(loadper>=100) { 
      preLoader_mc.perct_mc.visible=false;
      loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loader);
   }
}

Just listen out for Event.COMPLETE which triggers once the file has fully loaded. 只需侦听Event.COMPLETE ,该事件将在文件完全加载后触发。 Along with a few other tweaks: 以及其他一些调整:

loaderInfo.addEventListener(ProgressEvent.PROGRESS, loaderProgress);
loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);

function loaderProgress(event:ProgressEvent) { 
    var percentage:Number = Math.round((stage.loaderInfo.bytesLoaded / stage.loaderInfo.bytesTotal) * 100);
    _txt.text = percentage + "%";
}

function loaderComplete(event:Event):void
{
    loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loaderProgress);
    loaderInfo.removeEventListener(Event.COMPLETE, loaderComplete);

    preLoader_mc.perct_mc.visible = false;
}

In the same event there is the information about total bytes. 在同一事件中,存在有关总字节的信息。

You can have it as 你可以拥有它

filename.bytesTotal

where filename is your event variable as per your code. 其中filename是根据代码的事件变量。

By doing 通过做

filename.bytesLoaded / filename.bytesTotal

you have the percent completion. 您有完成百分比。 This would never enter an infinite loop. 这将永远不会进入无限循环。

You can check more detailed information on adobe's documentation and examples here . 您可以在此处查看有关Adobe文档和示例的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM