[英]AS3 load symbol from external swf library
I have 2 SWF, one of them (let's call it Resources.swf
), that contains several symbols (most of them MovieClips) on its library, but, none of them are added into the stage ( the timeline contains only one empty frame), and then, the other swf ( Main.swf
), where I need to import some of the symbols from the other SWF.我有 2 个 SWF,其中一个(我们称之为
Resources.swf
),在其库中包含多个符号(大多数是 MovieClips),但是,它们都没有添加到舞台中(时间轴只包含一个空帧) ,然后是另一个 swf ( Main.swf
),我需要从另一个 SWF 导入一些符号。
I have been looking around, and searching, but all the info that I saw, and tried, imports the symbols from the stage/timeline using things like:我一直在环顾四周,搜索,但我看到并尝试过的所有信息都使用以下内容从舞台/时间轴导入符号:
loadedMC = MovieClip(loader.content);
or或者
loadedMC = MovieClip(event.target.content);
My symbols have a class definition, because, they are also used in other swf this way:我的符号有一个 class 定义,因为它们也以这种方式在其他 swf 中使用:
[Embed(source='assets/Resources.swf', symbol='SymbolName')]
public class Generic2 extends MovieClip
Is there any way to do this?有没有办法做到这一点?
If not,do I have modify my Resources.swf to work this out or do I have other alternatives?如果没有,我是否修改了我的 Resources.swf 来解决这个问题,或者我有其他选择吗?
After loading the Resources.swf you can create instances of the loaded classes.加载 Resources.swf 后,您可以创建加载类的实例。
Here a snippet that may help:这里有一个片段可能会有所帮助:
var dynClass : Class = Class(getDefinitionByName("fully.qualified.ClassName"));
if(dynClass)
{
var app : Object = new dynClass();
addChild(app as DisplayObject);
}
Follow these steps按着这些次序
Helper Function帮手 Function
public function createInstance(mc:MovieClip, className:String, instName:String):MovieClip
{
var cls:Class = mc.loaderInfo.applicationDomain.getDefinition(className) as Class;
if (cls)
{
var instMC:MovieClip = new cls();
instMC.name = instName;
return instMC;
}
return null;
}
You need to have a as3 class, or just to export the symbol in the frame otherwise you can't reference it.您需要有一个 as3 class,或者只是导出框架中的符号,否则您无法引用它。 Your swf will be empty if you don't export your movieclip... Basically you can just export it as a Certain class and then reference the empty class!
如果您不导出影片剪辑,您的 swf 将为空...基本上您可以将其导出为某个 class 然后引用空类!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.