0
我被迫與ActionScript/Adobe Air合作。來自Java背景。我無法弄清楚我在這裏做錯了什麼,也許有人可以幫忙。基本上我想這個函數返回它提取的XMLNode
。爲什麼我不能從函數內部修改這個變量?
public function getXmlWebpage(address:String):XMLNode {
var service:HTTPService = new HTTPService();
var xmlResult : XMLNode = null;
service.method = "GET";
service.url = address;
service.resultFormat = HTTPService.RESULT_FORMAT_XML;
function onResult(result:ResultEvent):void{
trace("status code " + result.statusCode);
var node : XMLNode = result.result as XMLNode;
trace("node has NS URI " + node.namespaceURI);
xmlResult = node;
}
function onFail(event:FaultEvent):void{
trace("fail function of getXmlWebpage called.");
Alert.show("error communicating with host " + event.fault.toString());
}
service.addEventListener(FaultEvent.FAULT, onFail);
service.addEventListener(ResultEvent.RESULT, onResult);
service.send(null);
trace("return value will be " + xmlResult)
return xmlResult;
}
但日誌說(是的,按照這個順序):
return value will be null
status code 200
node has NS URI http://www.w3.org/2005/Atom
什麼我沒有得到嗎?我不能修改xmlResult
從onResult
?