简体   繁体   English

AS3-如何从外部SWF加载MovieClip资产

[英]AS3 - How to load MovieClip assets from an external SWF

I exported a SWF file from an FLA with weather icons (as MovieClips) in the library. 我从FLA中导出了带有天气图标(如MovieClips)的SWF文件。 The linkage names are "IconX" (where X is the icon number from 0 to 25). 链接名称为“ IconX”(其中X是从0到25的图标编号)。

I want to use these icons on other templates... how can I load a specific MofieClip asset into a new template? 我想在其他模板上使用这些图标...如何将特定的MofieClip资产加载到新模板中?

The SWF with the icons is called TP1023.swf and sits in the same place where the other templates will be. 带有图标的SWF称为TP1023.swf,位于其他模板所在的位置。

The simplest way is to set a method in the loaded SWF that will return what you are asking for. 最简单的方法是在已加载的SWF中设置一个方法,该方法将返回您的要求。 ie: 即:

public function getAsset(classId:String):DisplayObject {
    var c:Class = Class(getDefinitionByName(classId));
    if (!c) {
        trace("ERROR: class " + classId + " not found.");
        return null;
    }
    var d:DisplayObject = new c() as DisplayObject;
    if (!d) {
        trace("ERROR instantiating " + classId);
        return null;
    }
    return d;
}

I assumed it has to be general purpose, so it returns a DisplayObject. 我认为它必须是通用的,因此它返回一个DisplayObject。 You can use other types too. 您也可以使用其他类型。 Once you loaded the SWF and it is correctly initialized, you can retrieve any element you want: 加载SWF并正确初始化之后,您可以检索所需的任何元素:

var c:MovieClip = loadedSwf.getAsset("MyAssetId") as MovieClip;

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

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