Normally, you listen for dragDrop or dragComplete events and if you
don't want default behavior, you call preventDefault on the event and do
whatever you want.
So, if I were handling dragging products to a shopping list, I would
write something like this:
public function dragDropHandler(event:DragEvent):void
{
var draggedItems:Array =
event.dragSource.dataForFormat("items");
var draggedItem:Product = draggeItems[0];
// search array collection for existing object
var ac:ArrayCollection = dataProvider;
var n:int = ac.length;
for (var i:int = 0; I < n; i++)
{
If (ac[i].productKey == draggedItem.productKey)
{
ac[i].quantity ++;
event.preventDefault();
return;
}
}
// if we don't exit via preventDefault()/return, then
default behavior will add it to the dataProvider
}
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of bredwards358
Sent: Friday, May 30, 2008 8:45 AM
To: [email protected]
Subject: [flexcoders] Questions regarding updating dataProviders after a
drag & drop
Looking through the posts regarding my search criteria of drap and drop
and Array collection, I couldn't find a post which cleared up the task
of updating a data provider, in this case, an array collection, after an
item is dragged to its datagrid from another. Purely using the default
settings(no code other than the settings in the MXML tags), I can drag
an object from one grid to another and have that item appear perfectly
in there barring a few things I plan to add after the fact. What I'm
guessing, and please correct me if I'm wrong, but I would need to invoke
an event through the dragDrop or dragComplete events? Also would I be
correct to assume that the skeleton of such a function would look like
this?
private function dragToOrders(event:DragEvent):void
{
//Insert whatever logic to happen when the event happens
}
Where I'm getting stuck the most is the logic inside that skeleton, I
have a rough idea on what would happen with this:
orderDetailArray.addItem(/*What represents the item being dragged?*/);
orderDetailArray.Refresh();
Would this be at least close to correct? Also, since the items being
dragged are products, I'd need to find a way to simply increment a field
in the dataprovider instead of adding another row of the exact same
thing, though I believe this is a simple check to see if the item being
added is the same as something already in the arraycollection via a
loop.
If this seems vague then place let me know so we can clear this up,
also, pointers to posts I may have missed, blogs or tutorials on similar
subject matter would help. Thanks in advance,
Brian Ross Edwards
Tech-Connect LLC