在 ActionScript 中编译时嵌入/导入 SWC,无需设置库路径

发布于 2024-10-21 12:06:19 字数 820 浏览 1 评论 0原文

冰雹,斯塔克!

我在弄清楚如何直接在 ActionScript 中导入 SWC 文件而不设置文件的库路径时遇到了一些麻烦。

举个例子,我需要这样的东西:

package
{
    [Embed(source = 'Library.swc')] // This line won't work, of course...

    import ClassInsideSWC;

    public class MyClass extends ClassInsideSWC
    {
        public function MyClass()
        {
            super();
        }
    }
}

此外,我不想(事实上我不能)通过使用 Loader 类加载 SWC 来导入它。

那么,有人知道一种仅使用 ActionScript 代码链接到 SWC 的方法吗?


编辑

只是为了添加有关问题的更多信息,我将用更多详细信息展示我的场景...

我有一个类 SubClass ,它将独立于其余部分。 它将扩展 SWC/SWF 内部的类 SuperClass...

该 SWC/SWF 具有整个框架。 我无法编译单个 SWF 中的每个类。 我的框架的每个部分都是一个 SWF,将在运行时由 Loader 类下载。

可悲的是,@frankhermes 的答案不起作用。 该方法不会下载类,并且不允许我扩展或使用 SWC 内的其他类。

如果我设置库路径,这就成为可能......

Hail, Stack!

I'm having a little trouble figuring out how to import a SWC file directly in ActionScript, without setting a library path to the file.

To exemplify, I need something like this:

package
{
    [Embed(source = 'Library.swc')] // This line won't work, of course...

    import ClassInsideSWC;

    public class MyClass extends ClassInsideSWC
    {
        public function MyClass()
        {
            super();
        }
    }
}

Besides, I don't want to (I can't, in fact) import the SWC by loading it with Loader class.

Well, someone knows a way to link to the SWC using only ActionScript Code?


Edited

Just to add more info about the problem, I'll showcase my scenario with more details...

I have a class SubClass that wil be independent from the rest.
It will extend a class SuperClass that is inside the SWC/SWF...

This SWC/SWF have the whole framework.
I can't compile every class inside a single SWF.
Every part of my framework is a SWF apart and will be downloaded by Loader class on runtime.

Sadly, @frankhermes answer won't work.
That method won't download the classes and won't allow me to extend or use other classes inside the SWC.

If I setup the library path this becomes possible...

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

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

发布评论

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

评论(2

小巷里的女流氓 2024-10-28 12:06:19

对 Sean Fujiwara 的答案的可能更正:

[Embed(source="SWFWireDecompiler.swc", mimeType="application/octet-stream")]
public var SWC:Class;

可能需要是:

[Embed(source="SWFWireDecompiler.swf", symbol="ClassInSWC")]
public class ClassInSWC
{
   ....
}

编辑:作为评论后的后续行动,这是获得可接受答案的另一次尝试:

package
{
    import flash.display.Sprite;

    public class SWCTest extends Sprite
    {
        public function SWCTest()
        {
            var extended:ExtendedCrumbs = new ExtendedCrumbs();
        }
    }

}

[Embed(source="../swfs/assets.swf", symbol="assets.Crumbs")]
class CrumbsInSWC
{

}

class ExtendedCrumbs extends CrumbsInSWC
{
    public function ExtendedCrumbs()
    {
        super();
    }

    // override something here
}

遗憾的是,它仅适用于 swf 文件,不适用于 swc 文件,因为你不能使用 swc 时,在 Embed 语句内使用 symbol="..."。但上面的代码确实可以编译。将 swf 文件放置在项目中的任意位置,并调整 Embed 语句内的源路径。

希望这对您仍然有用!坦率

A possible correction on Sean Fujiwara's answer:

[Embed(source="SWFWireDecompiler.swc", mimeType="application/octet-stream")]
public var SWC:Class;

might need to be:

[Embed(source="SWFWireDecompiler.swf", symbol="ClassInSWC")]
public class ClassInSWC
{
   ....
}

EDIT: as a follow-up after the comments, this is another attempt at getting an acceptable answer:

package
{
    import flash.display.Sprite;

    public class SWCTest extends Sprite
    {
        public function SWCTest()
        {
            var extended:ExtendedCrumbs = new ExtendedCrumbs();
        }
    }

}

[Embed(source="../swfs/assets.swf", symbol="assets.Crumbs")]
class CrumbsInSWC
{

}

class ExtendedCrumbs extends CrumbsInSWC
{
    public function ExtendedCrumbs()
    {
        super();
    }

    // override something here
}

Sadly it only works with swf files, not with swc's because you can't use symbol="..." inside Embed statements when using a swc. But the code above does compile. Place the swf file anywhere in your project and adjust the source path inside the Embed statement.

Hope this is still of some use to you! Frank

半世晨晓 2024-10-28 12:06:19

为什么你说“这条线行不通,当然……”?你几乎是对的,只是缺少一些东西。

[Embed(source="SWFWireDecompiler.swc", mimeType="application/octet-stream")]
public var SWC:Class;

然后你可以将数据作为 ByteArray 获取:

var data:ByteArray = new SWC();

Why do you say "This line won't work, of course..."? You're almost right, just missing a few things.

[Embed(source="SWFWireDecompiler.swc", mimeType="application/octet-stream")]
public var SWC:Class;

Then you can turn get the data as a ByteArray:

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