AS3加载屏幕 [英] as3 loading screen

查看:252
本文介绍了AS3加载屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建这些加载中,请稍候闪屏的加载条和百分比为你的SWF?请问AS3有一些内置的方法,还是应该从头开始设计的?

How do you create these "loading, please wait" splash screens with a loading bar and percentage for your swf? Does as3 have some built-in methods or should it be designed from scratch?

我的意思是,你怎么发现你的SWF文件被加载到客户端的浏览器?

I mean, how do you detect that your swf file is being loaded into client's browser?

呵呵,我有我的所有内容存储在只有一帧。纯AS3 code。

Oh and I have all my content stored in one frame only. pure as3 code.

推荐答案

如果您所有的code是在时间轴上,那么最简单的方法是使仅用于加载主SWF第二瑞士法郎。如果你的主SWF被称为的main.swf 中,code在加载SWF将是这样的:

If all of your code is on the timeline, then the easiest way is to make a second swf that is only used for loading your main swf. If your main swf is called main.swf, the code in your loading swf would be something like this:

//make a loader
var loader:Loader = new Loader()

//listen for loading progress
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//listen for when the load is finished
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

//load!
loader.load(new URLRequest("main.swf"));

function onProgress(event:ProgressEvent):void
{
    //calculate how much has been loaded
    var percentageLoader:Number = event.bytesLoaded / e.bytesTotal;

    //use your percentage number here to drive a loader bar graphic
}

function onComplete(event:Event):void
{
    //remove listeners now that loading is done
    loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);

    //add loaded swf to the stage
    addChild(loader.content);
}

顺便说一句,外化你的资产开辟了新的preloading可能性。而不必一切都在你的主SWF,你可以有你的主SWF加载外部资产,preLOAD这些资产。由于您的主SWF会那么小,就没有必要有第二个SWF只为您加载主SWF。

As an aside, externalizing your assets opens up new preloading possibilities. Instead of having everything in your main swf, you can have your main swf load external assets, and preload those assets. Since your main swf would then be small, there would be no need to have a second swf just for loading your main swf.

这篇关于AS3加载屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆