Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何加载带有嵌入式xml文件的.swf,然后从该xml文件实例化一个对象?_Xml_Actionscript 3_Flash - Fatal编程技术网

如何加载带有嵌入式xml文件的.swf,然后从该xml文件实例化一个对象?

如何加载带有嵌入式xml文件的.swf,然后从该xml文件实例化一个对象?,xml,actionscript-3,flash,Xml,Actionscript 3,Flash,基本上,我正在开发一款flash游戏,我希望能够将MOD加载到游戏中。每个mod都是一个.swf文件,其中包含一个嵌入的xml文件,该文件保存有关mod的所有信息(名称、版本、主类等),然后实例化该主类(扩展了类插件)。我有一个基本上我想怎么做的模型(根据我在Java中的经验),但我不太清楚嵌入之类的事情,有人能指导我吗 粗略的例子: //Loads the .swf file private var i:int = 0; private static function onLoadComple

基本上,我正在开发一款flash游戏,我希望能够将MOD加载到游戏中。每个mod都是一个.swf文件,其中包含一个嵌入的xml文件,该文件保存有关mod的所有信息(名称、版本、主类等),然后实例化该主类(扩展了类插件)。我有一个基本上我想怎么做的模型(根据我在Java中的经验),但我不太清楚嵌入之类的事情,有人能指导我吗

粗略的例子:

//Loads the .swf file
private var i:int = 0;
private static function onLoadComplete(e:Event) {
    //xml would (supposedly, not too sure how this works) be the embedded xml file
    var pluginMain:Class = getDefinitionByName(e.target.content.xml.Main[0]) as Class;
    var plugin = new pluginMain();
    //initiate() is a function of my class Plugin, which plugin should extend
    plugin.initiate(this);
    plugins[i] = plugin;
    i++;
}

通过使用具有正确MIME类型的
embed
标记,可以在SWF中嵌入XML文件。实例化时,直接在下面定义的类变量将包含嵌入文件的数据。下面是一个示例文档类,它嵌入一个XML文件,在加载时对其进行实例化,并在完成后发送一个“就绪”事件:

package  {

    import flash.display.Sprite;
    import flash.events.Event;

    public class Mod extends Sprite {

        [Embed(source="../xmldir/mod_data.xml", mimeType="application/octet-stream")]
        public var ModData:Class;

        public static const READY:String = "READY";

        public var modXml:XML;
        public var ready:Boolean = false;

        public function Mod() {
            data_init();
        }

        private function data_init():void {
            var modDataXML:XML = XML(new ModData());
            ready = true;
            dispatchEvent(new Event(READY));
            //trace(modDataXML.Main[0]);
        }

    }
}
您可以从您的
加载程序
内容
属性中侦听事件,或者检查
内容.ready
属性,以防它已被触发