在纯 Actionscript 3 项目中将 .swc 资源加载到数组中
我知道如何通过 .swc 将 Flash CS4 符号导入 Flash Builder。 类名在主类中可用,但我只能一一实例化它们,将每个名称写入代码中。
如何循环遍历 .swc 并将其资源加载到数组中而不提及其名称,然后获取并使用这些名称进行实例化?理想情况下,类似 (半途而废的伪代码):
the_instances: = new Array
for(i=0; i<the_SWC.length; i++)
{
tmp = new eval( the_SWC[i].name + '\(\)' )
the_instances.push( tmp )
}
或其他任何东西来在循环中获取这些名称。
I know how to get Flash CS4 symbols into Flash Builder via .swc.
The class names become available in the main class, but I can only instantiate those one by one, writing each name into the code.
How can I loop through the .swc and load its assets in an array without mentioning their name, then obtain and use these names for instantiation? ideally, something like (half-assed pseudocode):
the_instances: = new Array
for(i=0; i<the_SWC.length; i++)
{
tmp = new eval( the_SWC[i].name + '\(\)' )
the_instances.push( tmp )
}
or anything else to get those names in a loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你至少有2个选择。
选项1:
鉴于 SWC 文件是一个 zip 文件,其中包含一个带有嵌入资源的 swf 和一个描述内容的 xml 文件,您可以将 SWC 作为 zip 加载,获取 xml 并解析它。
我正在使用 nochump 库。
选项2:
由于您只需要类名来使您的喜欢更容易,并且您提到使用 Flash CS4(这让我假设您可以访问生成 SWC 的 .fla 文件),因此您可以编写一个简单的 jsfl 脚本来编写该行代码为你。
您需要做的就是:
文件>新的> Flash Javascript 文件并粘贴代码。
使用描述性名称将其保存在 Commands 文件夹中,例如:listExportClasses。
由于它位于“命令”菜单中,因此如果您经常使用它,则可以添加键盘快捷键。
该命令将生成一个包含 fla 文件名称的数组,并包含导出的类的名称,并将其方便地放置在剪贴板中。
例如
You have at least 2 options.
Option1:
Given the fact that a SWC file is a zip file that contains a swf with the embedded assets and an xml file describing the contents, you can load the swc as a zip, get the xml and parse it.
I am using the nochump library.
Option2:
Since you only need the class names to make your like easier and you mentioned using Flash CS4(which makes me assume you have access to the .fla file generating the swc), you can write a simple jsfl script that will write that line of code for you.
All you need to do is:
File > New > Flash Javascript File and paste the code.
Save it in the Commands folder with a descriptive name, like: listExportClasses.
Since it's in the Commands menu, if you use this often enough you could add a keyboard shortcut.
What the command will is generate an array with the name of the fla file and contain the exported classes' names and conveniently place it in your clipboard.
e.g