參數傳遞給事件處理程序我有這樣的代碼:AS3的HTTPService - 通過參考
var service:HTTPService = new HTTPService();
if (search.Location && search.Location.length > 0 && chkLocalSearch.selected) {
service.url = 'http://ajax.googleapis.com/ajax/services/search/local';
service.request.q = search.Keyword;
service.request.near = search.Location;
} else
{
service.url = 'http://ajax.googleapis.com/ajax/services/search/web';
service.request.q = search.Keyword + " " + search.Location;
}
service.request.v = '1.0';
service.resultFormat = 'text';
service.addEventListener(ResultEvent.RESULT, onServerResponse);
service.send();
我想通過搜索對象的結果方法(onServerResponse),但如果我在一個封閉做到這一點它得到按價值傳遞。有沒有辦法通過引用來做到這一點,而無需搜索結果中返回的值的搜索對象數組?
我想將搜索傳遞給onServerResponse。 – Shawn 2010-04-10 15:20:16
是的,但我不明白爲什麼使用閉包方法不起作用。我想也許你想從你的數組中刪除搜索對象,在這種情況下,你需要訪問數組。否則,您將得到的搜索參數是對原始對象的引用的副本。只要你使用引用,你就可以訪問原始對象。所以,如果你想改變搜索對象的值或者調用一些方法,你應該沒有問題。 – 2010-04-10 15:30:50
不,我得到一個對象副本的引用,而不是引用的副本。 – Shawn 2010-04-27 20:22:22