我在使用flash创建的类中存在范围问题。我正在创建一个应用程序,它利用XML来创建一系列信息,我将操纵并重新保存到XML中。AS3范围问题
我有一个文档类调用调用另一个类,我正在使用加载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;
}
}
}
似乎很简单,但我似乎无法编辑阵列。文档类总是返回一个空白数组。有任何想法吗?
你是最棒的!感谢你的帮助。我是面向对象编程的新手,我刚开始看到它有多强大。 – Laurence 2011-05-04 05:24:11