配列を作成しました。
その配列内の各アイテムを取得し、そのアイテムに対していくつかの計算を実行し、結果を配列にプッシュしてから、配列内の次のアイテムに移動する必要があります。
計算は別のクラスで行われます。次に、計算が完了したら、イベントをディスパッチし、クラスが完了するのをリッスンします。
forEach を使用していますが、forEach 関数を一時停止し、dispatchEvent リスナーを待ってから続行する必要がありますが、機能していないようです。
トレースは、forEach が配列を実行し、毎回計算クラスをリセットしていることを示唆しているようです。
これが私のコードの要旨です。サーバー上の 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);
}