플래시에서 생성 된 클래스의 범위에 문제가 있습니다. 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