简体   繁体   English

AS3 从外部 swf 库加载符号

[英]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按着这些次序

  1. In flash, mark your class for export by bringing up "Properties" for the library item and checking "Export for ActionScript" and giving it a "Class" name.在 flash 中,将 class 标记为导出,方法是调出库项目的“属性”并选中“导出为 ActionScript”并为其指定“类”名称。
  2. Publish Resources.SWF发布资源.SWF
  3. After loading Resources.SWF, you can create instances with this helper function加载 Resources.SWF 后,您可以使用此帮助程序 function 创建实例
  4. You can then addChild() or whatever you want with the instance.然后,您可以 addChild() 或任何您想要的实例。

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.

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