【发布时间】:2011-05-04 02:16:35
【问题描述】:
我在使用 Flash 创建的类中遇到了范围问题。我正在创建一个应用程序,该应用程序利用 XML 来创建我将操作并重新保存到 XML 的信息数组。
我有一个文档类正在调用另一个类,该类用于加载 XML,将其转换为数组并使用方法将数组返回给文档构造函数。我已成功解析 XML 并创建了一个数据数组,但似乎无法通过 loadXMLData 类中的 processXML 函数将数据添加到数组中。
我从代码中删除了所有无关紧要的内容。这是我正在尝试做的基本表示。
我的文档类
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.*;
public class dashBoard extends MovieClip {
public var newData
//initialize the dashBoard
public function dashBoard(){
//construct the Dashboard Object
trace("Dashboard Initialized");
trace("|--------------XML Data--------------|");
newData = new loadXMLData();
trace(newData.getSections());
}
}
}
我的 loadXMLData 类
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.*;
public class loadXMLData extends MovieClip {
//initialize an array that will be used in the document class
public var sectionList:Array = new Array();
public function loadXMLData() {
//load the xml file containing the data
var myLoader = new URLLoader();
myLoader.load(new URLRequest("dashboard.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
//process the xml file after it loads
//and create an object
var newXML:XML = new XML(e.target.data);
//then I use the XML to populate my
//array i declared at the top
//this is a simple test
sectionList[0] = "test";
}
}
//and this is the method i use in the document class
//to get the sectionList array
public function getSections():Array{
return sectionList;
}
}
}
看起来很简单,但我似乎无法编辑数组。文档类总是返回一个空白数组。有什么想法吗?
【问题讨论】:
标签: xml arrays actionscript-3 oop