Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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文件读取器类不工作?_Xml_Actionscript 2 - Fatal编程技术网

为什么我的xml文件读取器类不工作?

为什么我的xml文件读取器类不工作?,xml,actionscript-2,Xml,Actionscript 2,我试图在actionscript文件中创建一个简单的类,用于处理xml文件的读入和解析/管理。此类将movieclip作为参数,并使电影剪辑根据导入的结果进行操作。我试过这个: class FileReader { var menu:MovieClip; function FileReader(newMenu) { menu = newMenu; } //Load the specified xml file function loadFi

我试图在actionscript文件中创建一个简单的类,用于处理xml文件的读入和解析/管理。此类将movieclip作为参数,并使电影剪辑根据导入的结果进行操作。我试过这个:

class FileReader {
    var menu:MovieClip;
    function FileReader(newMenu) {
        menu = newMenu;
    }
    //Load the specified xml file
    function loadFile(fileName) {
        menu.gotoAndStop("loading");
        var name = levelName+".xml";
        var xmlFile = new XML();
        xmlFile.ignoreWhite = true;
        xmlFile.load(name);
        xmlFile.onLoad = function() {
            //Parse Input
            menu.gotoAndStop("loaded");
        };
    }
}
class FileReader {
    var menu:MovieClip;
    var xmlFile:XML;
    function FileReader(newMenu) {
        menu = newMenu;
    }
    //Load the specified xml file
    function loadFile(fileName) {
        menu.gotoAndStop("loading");
        var name = fileName+".xml";
        xmlFile = new XML();
        xmlFile.ignoreWhite = true;
        xmlFile.load(name);
        xmlFile.onLoad = function() {
            //Parse Input
            menu.gotoAndStop("loaded");
        };
    }
}
出于某种原因,当代码到达onLoad函数时,文件将正确加载,但应用程序不再知道菜单movieclip的存在。如果我试图跟踪菜单的任何属性,它会说它是未定义的。于是我尝试了这个:

class FileReader {
    var menu:MovieClip;
    function FileReader(newMenu) {
        menu = newMenu;
    }
    //Load the specified xml file
    function loadFile(fileName) {
        menu.gotoAndStop("loading");
        var name = levelName+".xml";
        var xmlFile = new XML();
        xmlFile.ignoreWhite = true;
        xmlFile.load(name);
        xmlFile.onLoad = function() {
            //Parse Input
            menu.gotoAndStop("loaded");
        };
    }
}
class FileReader {
    var menu:MovieClip;
    var xmlFile:XML;
    function FileReader(newMenu) {
        menu = newMenu;
    }
    //Load the specified xml file
    function loadFile(fileName) {
        menu.gotoAndStop("loading");
        var name = fileName+".xml";
        xmlFile = new XML();
        xmlFile.ignoreWhite = true;
        xmlFile.load(name);
        xmlFile.onLoad = function() {
            //Parse Input
            menu.gotoAndStop("loaded");
        };
    }
}

在这种情况下,根本不会加载xml文件,并且xmlFile对象未定义。这里发生了什么?为什么这两种方法都不起作用?

通过使用第一种方法,我发现我可以简单地将电影剪辑作为参数传递。然后,该功能将识别电影剪辑,并按预期正确操作。仍然不明白为什么没有参数通过它就不能工作

编辑:
我想这并不像我想的那样有效。不过我还在努力!有人有其他想法吗?

这有点傻,但我终于找到了一种方法来实现这一点:

class FileReader {
    var menu:MovieClip;
    function FileReader(newMenu) {
        menu = newMenu;
    }
    //Load the specified xml file
    function loadFile(fileName) {
        menu.gotoAndStop("loading");
        var newMenu:MovieClip = menu;   //Make a refernce to menu here
        var name = levelName+".xml";
        var xmlFile = new XML();
        xmlFile.ignoreWhite = true;
        xmlFile.load(name);
        xmlFile.onLoad = function() {
                //Parse Input
                newMenu.gotoAndStop("loaded"); //Call the refence rather than the actual object
        };
    }
}
通过对菜单进行新的引用,onLoad功能可以使用此引用与实际的菜单电影剪辑对话。我想这是可行的