如何从函数中获取外部 swf 文件的所有 SymbolClass 名称?

问题描述 投票:0回答:1

我有这个问题,我在一个网站上托管了几个

swf files
,我想创建一个函数来返回某个
SymbolClass
的所有
swf file
名称,并通过参数指定它:

像这样的东西:

var request:URLRequest = new URLRequest("https: //myweb.com/assets/" + param1 + ".swf");

假设我有一个

swf
叫:

Food.swf
”和它的 SymbolClass 是:
"Hamburger", "Potatoes", "HotDog"
,如果我通过该函数的参数指定另一个
swf
,我希望函数返回这些名称和相同的方式。

actionscript-3
1个回答
1
投票

好的,首先,您只能在加载有问题的SWF之后获取此信息,而不是之前。

我没有办法测试,但应该可能如下工作:

import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.utils.describeType;
import flash.system.ApplicationDomain;

var aRequest:URLRequest = "Food.swf";
var aLoader:Loader = new Loader;

// Use the INIT event rather than COMPLETE.
// COMPLETE only indicates that all the bytes are loaded.
// INIT is fired AFTER the loaded SWF renders its first frame,
// and that means all the content (classes) should be available at that moment.
aLoader.contentLoaderInfo.addEventListener(Event.INIT, onLoaded);
aLoader.load(aRequest);

function onLoaded(e:Event):void
{
    // Release the event binding.
    aLoader.contentLoaderInfo.removeEventListener(Event.INIT, onLoaded);
    
    // Let's see what's inside the loaded SWF.
    
    // First, let's grab the dedicated object that lists all the classes.
    var aDomain:ApplicationDomain = aLoader.contentLoaderInfo.applicationDomain;
    
    // Second, let's get the list of class names.
    var aList:Vector.<String> = aDomain.getQualifiedDefinitionNames();
    
    trace("There are", aList.length, "(probably) classes in the");
    trace(">>>", aLoader.contentLoaderInfo.url);
    
    // Now we have them all. Let's see what's there.
    for each (var aName:String in aList)
    {
        var aClass:Class = aDomain.getDefinition(aName);
        var aDescription:XML = describeType(aClass);
        
        // Output the catch.
        trace();
        trace();
        trace(aName);
        trace();
        trace(aClass);
        trace();
        trace(aDescription.toXMLString());
    }
}

一些参考调查,如果上面的脚本不起作用:

© www.soinside.com 2019 - 2024. All rights reserved.