Hey Flex Experts,
I'm having yet another issue with dragging of items in my List. This time it's not performance related Here's the issue - I need to stop the user from dragging certain items within the list. These items are effectively locked in their position. I also need to do some custom positioning of items when they are dropped into the list. I can handle the second problem just fine, the issue is trying to stop an item from being moved.
I was initially letting Flex handle all the drag and drop and I was stopping the List item from being moved by listening for a MouseMove event on the itemRenderer, and if the item was locked I was setting dragEnabled to False. This worked, however it made solving the second problem very difficult for various reasons. I decided I would take on the approach of handling all the dragging and dropping myself by overriding all the drag and drop methods on my list. This works great for the second problem, however it's bringing up an issue with the first problem (item locking).
Using samples I found, I was initating DragManager.doDrag(....) on the mouseMove event that's fired off by the itemRenderer. I was able to check if the item was locked, and if so I would set dragEnabled to False (just like before). However, if I started to drag that item and then, while "dragging" (I wasn't actually dragging anything), I moved my mouse over an unlocked item the locked item would start to drag (because the itemRenderer that fired off the mouseEvent was not locked, so dragEnabled was getting set to true). I also noticed a decent performance using this approach because my logic (there's a lot of it in the mouseMove) was getting fired everytime I moved the mouse - this is no good as I could have over 200 items in the list!
I then thought I could check to see if the itemRenderer that got the mouseMove event was the item that was selected in the list, if so I would do my logic and if not I would just ignore the event. This would work, except we allow the selection and dragging of multiple items. I could check to see if the item that got the mouseMove event is in the list of selected items, but this doesn't help the situation where I have a locked item and a non-locked item selected as I could just move the mouse over the non locked item while "dragging" to get dragEnable to set to true. I could add additional logic to the mouseMove event, but it's already pretty packed with logic and I'm affraid adding even more might make things more complicated then need be.
So this leads me to where I am now. I had an idea that if I handled the logic on the mouseDown event of the itemRenderer instead of the mouseMove event, I could get around the dragging issue and also speed the application up because all the business rule logic would only run once (on mouseDown) instead of all the time (on mouseMove). I am, however, now having another enitrely different issue. It seems the itemRenderer gets the mouseDown event before the parent list knows it's selected. So when I go to create my dragProxy (using List.createDragIndicator), the first time I attempt to drag something no indicator is displayed (because no item is selected, so the list thinks). The second (and any time after that) time I attempt to drag the slide, it works just fine until I switch selection. If I select the second item, and then attempt to drag the third, I get a dragIndicator (ghost) image of the second slide and not the third. When I look at the selectedItems array at that time, I see the list still thinks the second item is selected.
Whew - with all that said, is there maybe a better way to tackle these issues? If I listen on the parent list for the mouseDown event, instead of on the itemRenderer and bubbling it, would the item that was clicked be selected before I got the event? If so, would I be able to find out which item was "mouseDown-ed" on without using selectedItem (as there could be multiple selected items)? I did my best to describe the issue as completely as possible - I apologize if I was not clear. I was going to post a sample application, but I'm not sure that would help make things clear as I would have to post all the different business rule logic for anything to make real sense.
Many thanks in advance