2014-09-11 79 views
-3

我的事件處理程序有問題。我正在嘗試使用URLRequest從數據庫加載一些數據。但它陷入了無限循環。即使在加載所有數據之後,爲什麼還要循環呢?AS3事件處理程序陷入無限循環

結果被推入數組中。

代碼:

public function Listingdetailinfo() 
{ 
    somedata = SearchVectorTest.lists; 
    SrSend = new URLRequest("http://testurl/requestimage.php"); 
    SrSend.method = URLRequestMethod.POST; 
    Arvariables = new URLVariables ; 
    SrSend.data = Arvariables; 
    SaLoader = new URLLoader(); 
    SaLoader.dataFormat = URLLoaderDataFormat.TEXT; 

    Arvariables.data1 = somedata[0]; 

    SaLoader.load(SrSend); 
    SaLoader.addEventListener(Event.COMPLETE,Asandler); 

    function searchVOs(pic:String) 
    { 
     this.pic = pic; 
    } 

    function Asandler(event:Event):void 
    { 
     trace(event.target.data); 
     // retrieve data from php call 
     var resultString:String = event.target.data; 

     trace(event.target.data); 

     // parse result string as json object and cast it to array 
     var resultArray:Array = JSON.parse(resultString) as Array; 

     var len:int = resultArray.length; 

     trace(resultString); 

     // create vector of SearchVO 
     var searchVOs:Array = new Array(); 

     // get the length of the result set 
     var i:int; 
     for (i=0; i<len; i++) 
     { 
      searchVOs[i] = new Listingdetailinfo(); 
      searchVOs[i].pic = resultArray[i].pic; 

      myArray.push(searchVOs[i].pic); 
     } 

    } 
} 
+0

嘗試更加嚴格的代碼格式。我在另一個問題上爲你解決了它。很難閱讀像上面這樣的代碼 – Ingweland 2014-09-11 07:27:14

+0

嗨,對不起,當我複製代碼時,格式變得瘋狂。但我沒有任何框架。我只是嘗試了上面的代碼,沒有其他的東西,只是嘗試加載數據。它仍然陷在循環中。 – Ben 2014-09-11 07:30:10

回答

0

我假設你的代碼表示Listingdetailinfo類的構造函數。您的「無限循環」的原因是您正在創建此類的新實例

searchVOs[i] = new Listingdetailinfo();