2011-01-30 4 views
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 

을받지는 무엇입니까? xmlResultonResult으로 수정할 수 없습니까?

답변

3

getXmlWebpage 함수는 service.send가 반환되기를 기다리는 것을 차단하지 않습니다. 이 함수에서 원하는 값을 반환 할 수 없습니다. 오히려 onResult를 사용하여 결과를 게시하고 처리 할 수있는 콜백을 작성하십시오.

관련 문제