简体   繁体   English

Flash,ActionScript:从外部SWF加载资产

[英]Flash, ActionScript: Load assets from external SWF

We have a widget (SWF) that needs to be broken into two SWFs. 我们有一个小部件(SWF),需要将其分为两个SWF。 The main SWF will contain all the programming and business logic and it will also load a second SWF file which will contain the assets, fonts etc. 主SWF将包含所有编程和业务逻辑,还将加载第二个SWF文件,其中将包含资产,字体等。

I have limited experience in Flash but I know it can be done in Flex. 我在Flash方面的经验有限,但我知道可以在Flex中完成。 Anyway here we have to do it in Flash CS3. 无论如何,我们必须在Flash CS3中进行操作。 Will it be possible to do this in Flash? 可以在Flash中执行此操作吗? If yes, what are the steps we need to follow? 如果是,我们需要遵循哪些步骤?

Thanks, Sri 谢谢,斯里

When loading assets from an external SWF it is often useful to instantiate classes stored in the external SWF - for example Fonts are often accessed that way. 从外部SWF加载资产时,实例化存储在外部SWF中的类通常很有用-例如,通常以这种方式访问​​字体。

When doing such, you have to make sure that your local SWF has the definition of these classes, and simply compiling both SWF files together does not guarantee that. 这样做时,必须确保本地SWF具有这些类的定义,并且仅将两个SWF文件一起编译并不能保证这样做。 More specifically, if on SWF is dependent on classes in another, then both SWF files end up carrying copies of the class definitions and when you load the external SWF file in the runtime you get casting errors because the VM doesn't know that the same named class in an external SWF is the exact same as the one you have. 更具体地说,如果在SWF上依赖于另一个类,则两个SWF文件最终都携带类定义的副本,并且当您在运行时加载外部SWF文件时,您会遇到转换错误,因为VM不知道相同外部SWF中的命名类与您拥有的类完全相同。

In order to work around the problem you need to use ApplicationDomain.getDefinition() on the loaded SWF - see here for a detailed example . 为了解决该问题,您需要在加载的SWF上使用ApplicationDomain.getDefinition() -有关详细示例,请参见此处。 In addition to a detailed example on how to use Loader they also show how to get Class objects from an external SWF. 除了有关如何使用Loader的详细示例之外,它们还显示了如何从外部SWF获取Class对象。

Have a look at the Loader class. 看一下Loader类。 Code can be simpler than the one in the Example, but it's a start. 代码可能比示例中的代码简单,但这只是一个开始。 There is a well explained tutorial on the flashandmath.com website. flashandmath.com网站上有一个讲得很好的教程。

In you main fla ( with logic ), create a Loader, tell it to load the assets, on Event.INIT, use the assets. 在您的主文件中(带有逻辑),创建一个Loader,告诉它加载资产,在Event.INIT上,使用资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM