Hey guys... I'm working in a application were I need to let the user set the order of 3 panels using drag and drop. These panels are inside a container. The children of the container are another container that I don't need to do any of this (always in the position 0 of the children array) and the 3 panels to be dragged. The user should be able to drag a panel and drop it in the position he wants it to be, and the other panels should reorder. For example, if the user takes the first panel and wants to put it in the middle of the 3 panels, the second panel should take the place of the first panel and the dragged panel should be in the middle (position 2).
To do this I have a handler to the drop of the panel, and I calculate its new position through the y's of the panels. Once I have the new position I setChildIndex of the panel. Sometimes it works, sometimes it doesn't. When I put a panel in the middle of the bunch (panel.parent.setChildIndex(panel, 2)) it swaps the panels of the position 1 and 3. This should happen, because I dont set any other childIndex. For example, if a have A B and C in that order, and I want to put A in the middle it should be B A C, but it stays like this: C A B. It shouldn't switch B and C. Does anyone know why this happen? Here is the code for panel drop: private function panelDrop (event:FlexEvent):void { var menu:MyPanel = event.currentTarget as MyPanel; // panel that is being dropped. var position:int = 1; // it is initialized in 1, because in 0 there is no panel. for (var i:int = 0; i < pnl_container.numChildren; i++) // finds the new position of the dropped panel. { if (this.pnl_container.getChildren()[i] is MyPanel) // gets the child at i { var obj:MyPanel = pnl_container.getChildAt(i) as MyPanel; // child at i if ( menu.y > obj.y ) // if the y of the dropped menu is bigger than the child at position i, the position of the new panel is one lower. { position++; } } } menu.parent.setChildIndex(menu,position); // it sets the new position of the panel. I believe the problem is here. The problem is not searching the position, I have debugged and that is ok. } Thanx a lot guys =D