After fixing an issue regarding where best to put an insert function
call in my drag and drop function I now have another issue. It seems
that it is simply not seeing the most recently dropped item. For
instance, when I drop the very first item, it throws an error saying
that "0" (The index of the item being dropped) is out of bounds. This
error is thrown for every new item inserted afterward, when the second
item is inserted it will say that "1" is out of bounds. Interestingly
enough, updates to the ArrayCollection to change a value in that row
will still function perfectly. It seems that the row is not inserted
until the function is completely done, simply having something call a
value from the new row will not work as it simply isn't in yet. I feel
like this is a bit confusing so I'll go ahead and post my code complete
with debug functions I wrote to try and figure this out:

private function dragToOrders(event:DragEvent):void
{
     var draggedItems:Object = new Object();
     draggedItems =  event.dragSource.dataForFormat("items");
     var n:int = orderDetailArray.length;
        for (var i:int = 0; i < n; i++)//Looping through to check for
duplicate entries
        {
          if (orderDetailArray[i].ProductID == draggedItems[0].ProductID)
           {
             orderDetailArray[i].Qty ++;
             orderDetailArray.itemUpdated(orderDetailArray[i].Qty);
             trace("Fire update statement on " + i);
             tryUpdate(i);
             event.preventDefault();
             return;
           }
        }
        trace("Inserted New Record in " + i);
        tryInsert(i);
}
private function tryInsert(row:int):void
{
     try
     {
         trace("Value of Product: " + orderDetailArray[row].ProductID + "
was inserted at " + row);
     }
     catch(ex:Error)
     {
         if(orderDetailArray.length > 0)
         {
             trace(orderDetailArray[--row].ProductID);
         }
         trace(ex.toString());
         trace("----------\n" +
         ex.getStackTrace() +"\n"+
         "----------");
     }
}
private function tryUpdate(row:int):void
{
     try
     {
         trace("Value of Product: " + orderDetailArray[row].ProductID + "
was updated at " + row);
     }
     catch(ex:Error)
     {
         if(orderDetailArray.length > 0)
         {
             trace(orderDetailArray[row--].ProductID);
         }
         trace(ex.toString());
         trace("----------\n" +
         ex.getStackTrace() +"\n"+
         "----------");
     }
}

As usual, thanks in advance, any and all suggestions are greatly
appreciated.

Brian Ross Edwards
Tech-Connect LLC

Reply via email to