In the part of my application that I'm currently working on I'm trying
to dynamically update a local database every time a change is made to
the dataProvider(ArrayCollection) when a dragDrop action is done. Here's
my code so far:
-------------------
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].UniqueID == draggedItems[0].UniqueID)
           {
             orderDetailArray[i].Qty ++;
             event.preventDefault();
             adgOrders.dataProvider.dispatchEvent(new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
             trace("Update fired");//Placeholder foractual update
function
             return;
           }
           adgOrders.dataProvider.dispatchEvent(new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
           trace("Insert fired"); //Placeholder for actual insert
function
        }
}
-------------------
The problem is that both the insert and update "functions" are firing
once the second item is put into the dropTarget's dataProvider which
would cause many duplicate entries into the database. What I need help
with is making sure that only an insert or an update is fired when
needed. I suspect this may have something to do with the for loop
everything is in but outside input would be appreciated. Thanks in
advance,

Brian Ross Edwards
Tech-Connect LLC


Reply via email to