我已經填充了一個數組。AS3 dispatchEvent in forEach
我需要採取該數組中的每個項目,對該項目執行一些計算將結果推送到數組,然後移動到數組中的下一個項目,依此類推。
計算是在一個單獨的類中進行的。然後當計算完成時,我派遣一個事件並聽課以完成。
我正在使用forEach,但我需要暫停forEach函數並等待dispatchEvent偵聽器繼續,但我似乎無法得到它的工作。
跟蹤似乎表明,forEach只是運行數組並重新設置計算類。
這是我的代碼jist。我從我的服務器上的sql表填充數組,然後啓動forEach。
任何人都可以提出一個解決方案,請:
function handleLoadSuccessful(evt:Event):void
{
evt.target.dataFormat = URLLoaderDataFormat.TEXT;
var corrected:String = evt.target.data;
corrected = corrected.slice(1,corrected.length-1);
var result:URLVariables = new URLVariables(corrected);
if (result.errorcode=="0")
{
for (var i:Number=0; i < result.n; i++)
{
liveOrderArray.push(
{
code:result["ItemCode"+i],
qty:Number(result["LineQuantity"+i]) - Number(result["DespatchReceiptQuantity"+i])
})
}
liveOrderArray.forEach(allocate);
} else {
trace("ERROR IN RUNNING QUERY");
}
}
function allocate(element:*, index:int, arr:Array):void {
trace("code: " + element.code + " qty:" + element.qty);
allocationbible.profileCode = element.code.substring(0,1);
allocationbible.finishThk = Number(element.code.substring(1,3));
allocationbible.longEdgeCode = element.code.substring(3,4);
allocationbible.backingDetailCode = element.code.substring(4,5);
allocationbible.coreboardCode = element.code.substring(5,6);
allocationBible = new allocationbible;
allocationBible.addEventListener("allocated", updateAllocationQty, false, 0, true);
trace("*************************************");
}
function updateAllocationQty (evt:Event):void {
//add result to array
trace(allocationbible.coreboardLongCode);
}
element.code是一個30位商品代碼不同的子串等於不同的參數。根據這些參數,我計算出原材料的收益率,這是可分配計算的原材料。有沒有其他途徑比使用forEach?我指的是使用dispatchEvent獲取所需信息來計算分配的幾個sql表。 – user1344454 2012-04-19 17:13:32