如何在AS3的preloader工作?如何在、工作、preloader

2023-09-08 13:37:35 作者:官方认证我是帅比

我读过这个多的例子,但我只是不明白它是如何工作的。

如何类知道它的的在的pre-装载机? 如何闪存知道加载一个类,但不是其他? 在我多少钱可以做一个preloader? :磷

我使用的是FlashDevelop大气压,它的发电项目,我 - 然而,所有我检查,他们没有解释它是如何工作要么例子

解决方案

您熟悉Flash时间表?

默认情况下,SWF将有一帧。这个框架包含您的preloader.as类。 在编译时,FD创建第二个框架,其中包含主类 - 来运行你想要的类,一旦整个SWF已下载。 preloader.as包含code,它等待,直到所有的帧都已经完全下载,然后实例化的主类。

从 http://www.flashdevelop.org更多细节/community/viewtopic.php?f=9&t=5398 :

  

当你创建一个AS3项目,preloader,FD配置,你应该控制一些重要的事情:

         Flash as3加载 卸载外部swf或图片

在preloader.as,   有一个叫解决您的主类:   getDefinitionByName({限定主类名})

  

在项目属性,   编译器选项>附加编译器参数[...]   应该有:   -frame启动{限定主类名}

  

闪存知道先运行preloader.as因为FD所说的那样在第一帧,而FD做到这一点,因为preloader类已设置为始终编译(你可以选择设置这个选项自己通过右键单击一个类,然后选择始终编译)。

您可以做任何你喜欢的preloader,但它不会运行任何其code,直到需要的preloader已下载的一切。所以,如果你犯了一个preloader有3MB的图像文件和一个进度条,进度条将不会做任何事情,直到整个图像已经下载了!

I've read multiple examples on this, but I just don't get how it works.

How does the class know it's THE pre-loader? How does flash know to load one class but not another? How much can I do in a preloader? :-p

I'm using FlashDevelop atm and it's generating the project for me - however, from all the examples I checked they didn't explain how it worked either.

解决方案

Are you familiar with the Flash timeline?

By default, your SWF would have one frame. This frame contains your Preloader.as class. At compile-time, FD creates a second frame, which contains your Main class -- the class you want to be run once the whole SWF has downloaded. Preloader.as contains code that waits until all frames have been fully downloaded, and then instantiates the Main class.

More details from http://www.flashdevelop.org/community/viewtopic.php?f=9&t=5398:

When you create an "AS3 project with preloader", FD configures a few important things you should control:

in Preloader.as, There is a call to resolve your main class: getDefinitionByName("{qualified main class name}")

in Project properties, Compiler options > Additional compiler arguments [...] There should be: -frame start {qualified main class name}

Flash knows to run Preloader.as first because FD puts it in the first frame, and FD does this because the Preloader class has been set to "Always Compile" (you can choose to set this option yourself by right-clicking a class and selecting "Always Compile").

You can do whatever you like in a preloader, but it won't run any of its code until everything needed by the preloader has downloaded. So if you make a preloader with a 3MB image file and a progress bar, the progress bar won't do anything until the entire image has downloaded!