배열을 채 웁니다.AS3 dispatchEvent for 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 자리 코드가 다른 부분 문자열이 다른 매개 변수입니다. 이러한 매개 변수를 기반으로 원자재에 대한 생산량을 계산하고이 원자재가 allocationbible을 계산합니다. forEach를 사용하는 것보다 다른 경로가 있습니까? 할당을 계산하는 데 필요한 정보를 얻기 위해 dispatchEvent를 사용하는 여러 SQL 테이블을 참조합니다. – user1344454