在 ActionScript 中编译时嵌入/导入 SWC,无需设置库路径
冰雹,斯塔克!
我在弄清楚如何直接在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对 Sean Fujiwara 的答案的可能更正:
可能需要是:
编辑:作为评论后的后续行动,这是获得可接受答案的另一次尝试:
遗憾的是,它仅适用于 swf 文件,不适用于 swc 文件,因为你不能使用 swc 时,在 Embed 语句内使用
symbol="..."
。但上面的代码确实可以编译。将 swf 文件放置在项目中的任意位置,并调整 Embed 语句内的源路径。希望这对您仍然有用!坦率
A possible correction on Sean Fujiwara's answer:
might need to be:
EDIT: as a follow-up after the comments, this is another attempt at getting an acceptable answer:
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
为什么你说“这条线行不通,当然……”?你几乎是对的,只是缺少一些东西。
然后你可以将数据作为 ByteArray 获取:
Why do you say "This line won't work, of course..."? You're almost right, just missing a few things.
Then you can turn get the data as a ByteArray: