2012-12-05 1 views
1

내 httpservice (AS 클래스에서 정의 됨)에서 my mxml 응용 프로그램으로 결과를 얻으려고합니다. 모든 코드를 주 mxml에 넣었을 때 코드 자체가 잘 작동하지만 AS 클래스에서 작동하지 않는 것처럼 보입니다.httpservice를 ActionScript 클래스에서 쿼리

httpresult (myWatchedList = new XMLListCollection (myData.movie);)를 가져 오는 줄에 중단 점을 넣으면 myWatchedList에 원하는 값이 있음을 확인할 수 있습니다. 그러나 getWatchedList() 메소드를 호출하면 myWatchedList는 항상 null입니다.

내가 여기에 매우 뭔가를 분명 누락 확신 ... 클래스 AS

내 :

package components 
{ 

import mx.collections.XMLListCollection; 
import mx.rpc.events.ResultEvent; 
import mx.rpc.http.HTTPService; 

public class WatchList 
{ 
    [Bindable] 
    public var myToWatchList:XMLListCollection; 
    public var myWatchedList:XMLListCollection; 

    public function WatchList() 
    { 
     //httpservice for watched movies 
     var watchedList_service:HTTPService = new HTTPService(); 
     watchedList_service.url= "http://*****/phpscripts/selectWatchedlist.php"; 
     watchedList_service.showBusyCursor=true; 
     watchedList_service.resultFormat="e4x"; 
     watchedList_service.method="POST"; 

     //httpservice for not yet watched movies 
     var toWatchList_service:HTTPService = new HTTPService(); 
     toWatchList_service.url= "http://*****/phpscripts/selectToWatchlist.php"; 
     toWatchList_service.showBusyCursor=true; 
     toWatchList_service.resultFormat="e4x"; 
     toWatchList_service.method="POST"; 

     //listen for result 
     watchedList_service.addEventListener(ResultEvent.RESULT, watchedList_result); 
     toWatchList_service.addEventListener(ResultEvent.RESULT, toWatchList_result); 

     //send request to httpservice 
     toWatchList_service.send(); 
     watchedList_service.send();  

    } 

    public function toWatchList_result(event:ResultEvent):void 
    { 
     //result is xml 
     var myData:XML = XML(event.result); 
     myWatchedList = new XMLListCollection(myData.movie); 
    } 

    public function watchedList_result(event:ResultEvent):void 
    { 
     var myData:XML = XML(event.result); 
     myToWatchList = new XMLListCollection(myData.movie); 
    } 

    public function getWatchedList():XMLListCollection { 
     return this.myWatchedList; 
    } 

    public function getToWatchList():XMLListCollection { 
     return this.myToWatchList; 
    } 
} 
} 

MXML의 코드 :

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
      xmlns:components="components.*" 
      initialize="doSend()"> 
<s:layout> 
    <s:VerticalLayout paddingBottom="20" paddingLeft="20" 
         paddingRight="20" paddingTop="20"/> 
</s:layout> 
<fx:Script> 
    <![CDATA[ 
     import components.WatchList; 
     import mx.collections.XMLListCollection; 

     [Bindable] 
     private var myToWatchList:XMLListCollection; 
     private var myWatchedList:XMLListCollection; 
     private var watchList:components.WatchList; 
     protected function doSend():void 
     { 
      watchList= new components.WatchList(); 
      //fetch the watchlists 
      myToWatchList = watchList.getToWatchList(); 
      myWatchedList = watchList.getWatchedList(); 

      //bind the watchlists to the tilelist 
      myToWatchList_tile.dataProvider = myToWatchList; 
      myWatchedList_tile.dataProvider = myWatchedList; 
     } 


    ]]> 

</fx:Script> 
<fx:Declarations> 
</fx:Declarations> 
<s:Panel id="panel" width="100%" height="100%" title="Watchlist"> 
    <s:layout> 
     <s:VerticalLayout paddingBottom="5" paddingLeft="20" 
          paddingRight="20" paddingTop="5"/> 
    </s:layout> 
    <s:Label width="20%" fontSize="17" fontWeight="bold" text="Your watched movies"/> 
    <mx:TileList id="myWatchedList_tile" height="360" borderVisible="false" 
       columnCount="6" columnWidth="200" 
       itemRenderer="components.TileListItemRenderer" rowCount="1" rowHeight="360"/> 
    <s:Label width="20%" fontSize="17" fontWeight="bold" text="Your to watch movies"/> 
    <mx:TileList id="myToWatchList_tile" height="360" borderVisible="false" 
       columnCount="6" columnWidth="200" 
       itemRenderer="components.TileListItemRenderer" rowCount="1" rowHeight="360" /> 

</s:Panel> 

답변

0

먼저 요청을 한 생성자를 호출하십시오.

결과를 가져올 수 있습니다 이벤트를 던져 대기 핸들러합니다

myToWatchList = watchList.getToWatchList(); 

이 ... 당신이 요청이 완료 될 때까지 예를 들어, 기다려야한다 :

watchList= new components.WatchList(); 

은 즉시 그 후 당신은 결과를 전화 이벤트의 경우

+1

Thx이 작업이 이루어졌습니다. 지금 watchedList_result (event : ResultEvent)에 이벤트를 전달하고 내 mxml 앱에서이 이벤트를 수신합니다. – Steven

관련 문제