How to prevent "target swapping" of overlapping objects?

I’m working on creating a top-down product configurator or sorts, which is basically a grid with draggable objects. MOUSE_DOWN starts the drag of an object on the screen (calling a MOUSE_MOVE event) and MOUSE_UP stops the drag of an object. In this way a user can re-arrange any targeted object on the grid.

The problem is, when I drag objectA over objectB (which was placed on the grid earlier), they sometimes swap indexes (I’m assuming) and objectA will stop while objectB will begin dragging. The fact that the objects are of different dimensions only makes this worse. How can I prevent this from happening?

I thought about using setChildIndex() but I don’t see how I can make that work since the top-most item has the highest index value (if you have 5 things on the grid, the top one will have an index of 4 if I’m correct). The problem is I have an unlimited number of objects that can be placed on the grid, so I have no idea how I could figure out the highest index value.

Anyone have any ideas?