我在我的事件處理函數(函數執行期間)中爲我的xml對象(xml = new XML(e.currentTarget.data);)設置了一個值在event.COMPLETE之後),如果我跟蹤事件函數處理程序中的對象,它會顯示我的xml數據。Actionscript 3 - 如何在移除該事件後保留事件的值
但如果我嘗試在事件處理程序函數之外追蹤它,它不會顯示我的xml內容。沒有辦法讓我的xml對象內容值顯示在其他函數中,但不是在事件處理函數中顯示?
private var xml:XML;
public function XMLLoader(xmlURL:String)
{
var xmlURLRequest:URLRequest = new URLRequest(xmlURL);
var xmlURLLoader:URLLoader = new URLLoader(xmlURLRequest);
xmlURLLoader.addEventListener(Event.COMPLETE, xmlData);
}
private function xmlData(e:Event):void
{
e.currentTarget.removeEventListener(Event.COMPLETE, xmlData);
xml = new XML(e.currentTarget.data);
dispatchEvent(new Event(Event.COMPLETE));
trace(xml);
}
public function getXMLData():void
{
//I've find out that this shows null because this function is faster
//what do i do? put an event.complete in every following function?
trace(xml);
}
謝謝。
private var xml:XML; \t \t公共函數XMLLoader(XMLURL:字符串){ \t \t \t VAR xmlURLRequest \t:的URLRequest \t =新的URLRequest(XMLURL); \t \t \t var xmlURLLoader \t:URLLoader \t = new URLLoader(xmlURLRequest); \t \t \t \t \t \t xmlURLLoader.addEventListener(Event.COMPLETE,XMLDATA); \t \t} \t \t \t 私人\t功能XMLDATA(E:事件):無效{ \t \t \t e.currentTarget.removeEventListener(Event.COMPLETE,XMLDATA); \t \t \t \t \t \t xml = new XML(e.currentTarget.data); \t \t \t \t \t \t dispatchEvent(new Event(Event.COMPLETE)); \t \t \t trace(xml); \t \t} \t \t \t 公共\t功能getXMLData():無效{ \t \t \t跟蹤(XML); \t \t} – bunnyannihilator89
你可能會發布代碼,你安裝'XMLLoader'並調用'getXMLData()'方法嗎? –
public class XMLLoader extends EventDispatcher {\t \t private var xml:XML; \t公用函數XMLLoader(xmlURL:String){0} {0} {0} {0}} var xmlURLRequest:URLRequest = new URLRequest(xmlURL); \t \t var xmlURLLoader:URLLoader = new URLLoader(xmlURLRequest); \t xmlURLLoader.addEventListener(Event.COMPLETE,xmlData); \t \t} \t \t私有函數XMLDATA(E:事件):無效{ \t \t e.currentTarget.removeEventListener(Event.COMPLETE,XMLDATA); \t \t xml = new XML(e.currentTarget.data); \t \t dispatchEvent(new Event(Event.COMPLETE)); \t \t跟蹤(XML); //這一個顯示 \t \t} \t \t公共函數getXMLData():XML { \t \t \t跟蹤(XML); //這個不顯示 \t \t} \t} – bunnyannihilator89