I've populated an array.
i need to take each item in that array , perform some calculations on that item push the result to the array then move on to the next item in the array and so on.
The calculations are made in a separate class. Then when the calculations are completed i dispatch an event and listen for the class to complete.
I'm using forEach but i need to pause the forEach function and wait for the dispatchEvent listener before continuing but i can't seem to get it working.
Tracing seems to suggest that the forEach is just running through the array and resetting the calculation class each time.
Here is the jist of my code. I populate the array from a sql table on my server then initiate forEach.
can anyone suggest a solution please:
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);
}