如何有效加载SWF库?

发布于 2024-10-02 12:16:54 字数 416 浏览 6 评论 0 原文

我正在 FB4 中制作一个 AS3 项目。在我们的工作流程中,我们让艺术家将艺术作品编译成 SWC 文件,然后将其链接为 FB4 中的“参考库”。

然后我将 SWC 文件的“链接类型”设置为“外部”,而不是合并到代码中。这应该会在输出文件夹中创建与 SWC 文件相对应的 SWF,对吧?

事实似乎并非如此。我只看到一个 SWF 文件:main_app 的。

我试图做到这一点,以便我可以使用库管理器来加载文件动态地。

我尝试手动提取 swf,但似乎 main_app 仍然将所有 swc 编译到自身。我确保链接类型设置为外部。 “外部”和“合并到代码”之间的 main_app 文件大小似乎是相同的。

I am making an AS3 project in FB4. In our workflow, we have artists compile art into SWC files which the I then link as 'Referenced Libraries' in FB4.

Then I set the "Link Type" of the SWC files to "external" instead of merged into code. This should create SWFs corresponding to the SWC files in the output folder, right?

This doesn't seem to be the case. I am only seeing one SWF file: the main_app's.

I was trying to make it so that I can use a library manager to load the files dynamically.

I tried extracting the swfs manually, but it seems the main_app still compiles all the swcs to itself. I made sure the Link Type was set to external. The file size for the main_app between "external" and "merged to code" seem to be the same.

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

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

发布评论

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

评论(2

野心澎湃 2024-10-09 12:16:55

我在 Flash Builder 4 中创建了一个简单的项目,实现 SWC->SWF 的唯一方法是创建 Flex 项目而不是 ActionScript 项目,并选择“运行时共享库​​ (RSL)”而不是“外部” 。这是因为 Flex 框架有一些类可以为您加载这些库。它还可以自动执行转换(我应该说提取)过程。

现在,如果您不想为此创建 Flex 项目,您可以自己提取 SWF。 SWC 文件格式只是一个包含 SWF 和描述内容的 XML 文件的 Zip 文件。然后,您可以使用加载程序动态加载提取的 SWF 文件并设置正确的 应用程序域。这是我的示例项目的片段。

public class Web extends Sprite
{
    public function Web()
    {
        //you will not be able to instantiate classes of your library until it's loaded
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
        loader.load(new URLRequest("library.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
    }

    protected function onLoadComplete(event:Event):void
    {
        //here you can create instances of classes defined in your library
        new Asset();
    }

}

您可能会认为每次设计师更新库时解压+复制是一项相当乏味的工作。您可以使用脚本或 Ant 文件自动执行此过程。不幸的是,除非我遗漏了什么,否则 Flash Builder 似乎不希望您扩展构建过程,因此您仍然需要一些手工工作或完全转换为 Ant(或类似的东西)来构建。

祝你好运!

I've made a simple project in Flash Builder 4 and the only way I got the SWC->SWF happening is by creating a Flex Project instead of an ActionScript Project and selecting "Runtime shared library (RSL)" instead of "External". This is because the Flex framework have some classes that work out the loading of those libraries for you. It also automate the conversion (I should say extraction) process.

Now, if you don't want to create a Flex project just for this, you can extract the SWF yourself. The SWC file format is just a Zip containing a SWF and an XML file describing the content. You can then load dynamically this extracted SWF file using a Loader and setting the correct Application Domain. Here's a snippet of my sample project.

public class Web extends Sprite
{
    public function Web()
    {
        //you will not be able to instantiate classes of your library until it's loaded
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
        loader.load(new URLRequest("library.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
    }

    protected function onLoadComplete(event:Event):void
    {
        //here you can create instances of classes defined in your library
        new Asset();
    }

}

You might think that's a pretty tedious job to unzip+copy every time your designers update the library. You could automate this process with a script or an Ant file. Unfortunately, unless I'm missing something, it looks like Flash Builder doesn't want you to extend your build process, so you will still need a bit of hand work or completely convert to Ant (or something similar) to build.

Good luck!

情深已缘浅 2024-10-09 12:16:55

从 SWC 添加到您的库的那一刻起,您应该能够通过直接调用其特定的类名来访问 SWC 的资源。无需尝试获取 SWF 并使用 Loader 类加载它。这实际上违背了使用 SWC 的初衷!

假设,在您的 SWC 中,您有一个类名为 GraphicAsset 的 MovieClip,要创建一个新实例,您只需执行以下操作:

  var mc:MovieClip = new GraphicAsset();

在 FB4 的文件夹结构中,在 Referenced Libraries 文件夹和文件夹中查看您的 SWC。检查默认包,您应该看到所有资产的列表。

From the moment the SWC is added to your Library, you should be able to access the SWC's assets by directly calling their specific class names . There's no need to try to get a SWF and load it with the Loader class. This actually defeats the purpose of using a SWC in the first place!

Let's say that , in your SWC, you have a MovieClip with a class name of GraphicAsset, to create a new instance , you simply do this:

  var mc:MovieClip = new GraphicAsset();

In FB4's folder structure , have a look at your SWC in the Referenced Libraries folder & check the default package, you should see a list of all your assets.

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