2011-12-29 52 views
0

我建立一個數組:柔性移動接入陣列

var Detail:Array = new Array(getClass.detailArticle(brand, subgroup, name)); 

的方法:

public function detailArticle(brand:String, subgroup:String, name:String):Array 
    { 
     var sqlConnection:SQLConnection; 
     sqlConnection = new SQLConnection(); 
     sqlConnection.open(File.applicationStorageDirectory.resolvePath("assets/db.sqlite")); 
     var stmt:SQLStatement = new SQLStatement(); 
     stmt.sqlConnection = sqlConnection; 
     stmt.text = 
      "SELECT * FROM sen_updatesnew " + 
      "WHERE Brand= '" + brand + "' " + 
      "AND SubGroup= '" + subgroup + "' " + 
      "AND Name = '" + name + "' "; 
     stmt.execute(); 
     var result:Array = stmt.getResult().data; 
     return result;   
    } 

如何訪問元素?

細節[「element」]或Detail [0]沒有顯示任何內容。查詢正在順利進行。

我在做什麼錯?

回答

2

docs

如果響應參數不爲null指定Responder對象指定被調用來處理該操作的結果的方法。如果responder參數爲null,則在異步執行模式下,如果操作成功,則調度結果事件;如果操作失敗,則調度錯誤事件。

由於execute方法的空響應者參數,您必須在結果事件中監聽結果。這聽起來像你試圖在檢索結果之前訪問結果。


// make your result array an instance variable, not a functional local variable 
protected var result:Array ; 

// make this an instance variable so it can be accessed across methods 
protected var stmt:SQLStatement = new SQLStatement(); 

// this can't return anything because there is nothing to return at the time this method completes it's execution 
public function detailArticle(brand:String, subgroup:String, name:String):void 
{ 
    // some stuff 
    // add the event listener for the result event 
    stmt.addEventListener('result',onResult); 
    // other stuff 
    // no return statement 
} 


// the result handler 
protected function onResult(event:SQLEvent):void{ 
    result = stmt.getResult().data; 
} 
+0

在暫時無法訪問的文檔(你的鏈接)...你能給我在我的代碼示例什麼建議嗎?我正在爲這件事爭取幾個小時,並找不到解決方案... – Klaaz 2011-12-29 14:17:55

+0

我確認鏈接是正確的。我爲你一起扔了一些劃痕代碼,這是在我的答案。您需要進行一些研究以瞭解同步和異步調用 – JeffryHouser 2011-12-29 15:41:28

+0

之間的差異,謝謝!這真的幫助我! – Klaaz 2011-12-29 23:05:38