带有嵌入字节数组的 SWF 预加载器

发布于 2024-10-26 18:56:03 字数 87 浏览 0 评论 0原文

直到整个 SWF 完全加载后,编译的 SWF 才会显示预加载器。任何帮助都会非常感激,我用谷歌搜索了一整个晚上都找不到任何关于这方面的信息,至少对我来说是这样。

The complied SWF is not showing the preloader until the whole SWF completely loaded. Any hepl would be really appreciated, I googled the whole night couldnt find anything on this, at least for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁许谁一生繁华 2024-11-02 18:56:03

您无法将 ByteArray 嵌入到主文档类中,因为从文档类引用的类将自动包含在第 1 帧中。

预加载资源的最佳方法是拥有一个单独的 Preloader 类,并且主课。您希望 Preloader 类在第 1 帧上导出,而 Main 类和资源在第 2 帧上导出。

不幸的是,这比应有的更棘手,但您可以这样做:将文档类设置为 Preloader.此类包含您的 loaderInfo 代码。然而,当你完成加载时,不要直接实例化Main,即不要执行var main:Main = new Main()。无论您做什么,这都会自动导致 Main 被编译到第 1 帧。相反,间接实例化它,如下所示:

nextFrame(); // you sometimes need to do this for the player to register classes exported on frame 2
var mainClass:Class = flash.utils.getDefinitionByName("Main") as Class;
var main:Sprite = new mainClass();
addChild(main);

这将阻止编译器自动将 Main 拉到第 1 帧上。

接下来,如果您使用的是 Flash CS3+ IDE,请转至 File->Publish Settings->Flash->ActionScript 3.0设置并将“在帧上导出类”设置更改为第 2 帧。然后,在影片的第 2 帧上放置一个空的影片剪辑。在此 MovieClip 内,通过输入以下代码来放置对 Main 类的引用:var dummy:Main;。您必须这样做的原因是,编译器仍然知道您正在使用 Main,因此它实际上会将其编译到电影中,否则它根本不会编译它。您也不想将其放在主时间轴上,因为主时间轴上的任何代码引用都会自动拉到第 1 帧上。

在 IDE 中,检查内容是否已导出到正确位置的一个有用技巧是检查“在“发布属性”->“Flash”中“生成大小报告”。您可以检查报告,并且很容易注意到垃圾是否已导出到第 1 帧。

如果您使用 Flash Builder、FlashDevelop 或 FDT,则过程基本相同 - 创建单独的 Preloader 和 Main 类,并从 Preloader 间接实例化 Main 。但要通知编译器在预加载器之后在帧上编译 Main,请将此元标记放在 Main.as 中的 public class Main 之上:

[Frame(factoryClass="Preloader")]

FlashDevelop 还可以通过单击+ 在项目选项卡旁边。它将向您显示哪些资源已导出到哪些框架。理想情况下,您只需要在第 1 帧上使用最少的预加载器。

You can not embed the ByteArray into your main document class, because classes that are referenced from the document class will automatically be included on frame 1.

The best way to preload assets is to have a separate Preloader class and Main class. You want your Preloader class to export on frame 1, and your Main class and assets on frame 2.

Unfortunately, this is trickier than it should be, but here's how you can do it: Set your document class to Preloader. This class contains your loaderInfo code. However, when you finish loading, do not instantiate Main directly, i.e. do not do var main:Main = new Main(). This will automatically cause Main to be compiled onto frame 1 regardless of what you do. Instead, instantiate it indirectly, like this:

nextFrame(); // you sometimes need to do this for the player to register classes exported on frame 2
var mainClass:Class = flash.utils.getDefinitionByName("Main") as Class;
var main:Sprite = new mainClass();
addChild(main);

This will stop the compiler from automatically yanking Main onto frame 1.

Next, if you are using the Flash CS3+ IDE, go to File->Publish Settings->Flash->ActionScript 3.0 settings and change the "Export classes on frame" setting to frame 2. Then, on frame 2 of your movie, place an empty MovieClip. Inside this MovieClip, place a reference to your Main class by putting this code: var dummy:Main;. The reason you have to do this is so that the compiler will still know you are using Main, so it will actually compile it into the movie, otherwise it would not compile it at all. You also don't want to put this on the main timeline, because any code references on the main timeline automatically get yanked onto frame 1.

In the IDE, a helpful trick to check that things have exported in their proper place is to check "Generate size report" in Publish Properties->Flash. You can examine the report and will easily notice if junk has exported onto frame 1.

If you are using Flash Builder, FlashDevelop, or FDT, the process is basically the same--create separate Preloader and Main classes, and instantiate Main indirectly from Preloader. But to signal the compiler to compile Main on a frame after Preloader, put this metatag above public class Main in Main.as:

[Frame(factoryClass="Preloader")]

FlashDevelop can also introspect SWF files by click on the + beside it in the Project tab. It will show you what assets have been exported onto which frames. Ideally, you only want the bare minimum of Preloader on frame 1.

你怎么敢 2024-11-02 18:56:03

我已经在 CS4 中测试了 Mike 的方法。显然,引用 Main 的虚拟影片剪辑不需要位于第 2 帧上,也不需要位于时间轴上的任何位置。只要将虚拟影片剪辑设置为在第 2 帧上导出,Main 就会在第 2 帧上导出,因为虚拟剪辑的代码中引用了它。

I've tested Mike's method in CS4. Apparently the dummy movie clip that references Main doesn't need to be on frame 2, or anywhere on the timeline for that matter. As long as the dummy movie clip is set to export on frame 2, Main will export on frame 2 because its referenced in the dummy clip's code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文