views:

95

answers:

1

Hi, I've been working with the drag-and-drop of items inside an Horizontal List in Flex. It works fine, but now I need to save the new order through AMF in my database. I'm pretty sure it's quite easy, but I haven't figured it out yet.

Is there a way to cycle (after the reordering) all the items so that I can get for each item its (new) index?

And I noticed that even if I change the order, the order in the dataProvider is always the same...

This is my list:

<mx:HorizontalList id="horizontalList"
    allowMultipleSelection="true"
    allowDragSelection="true"
    dragEnabled="true"
    dropEnabled="true"
    dragMoveEnabled="true"
    labelField="lbl"
    iconField="src"
    itemRenderer="CustomItemRenderer_gallery"
    columnCount="5"
    columnWidth="125"
    rowHeight="125"
    horizontalScrollPolicy="on"
    doubleClickEnabled="true"
    click="{click(event);}"
    dragDrop="handleBtnReorder(event)"
    doubleClick="doubleClick(event);" />
A: 

I would just loop through the Lists dataProvider that you dragged the items onto... while looping store the new order (i) in a variable in your ArrayCollection populating the dataProvider... then convert the ArrayCollection to an array to be passed to your server side for processing.

something like:

for(var i:int = 0; i < yourList.dataprovider.length; i++)
{
     yourList.dataProvider.getItemAt(i).order = i;
}
// then convert the ArrayCollection to an Array and pass to your RemoteObject.
Chris Klepeis
I drag the items in the same list, and the dataProvider order doesn't change... I thought that there was some kind of native method, even something inherited from the List class.
Alberto Marcone
my mistake, I was using the wrong event, dragDrop.. at the dragComplete, the dataProvider has changed and I can do all the needed arrangements :) thank you!
Alberto Marcone