1 Reply Latest reply on Jul 19, 2010 4:40 PM by Medium_Aevum

    Reparenting UIComponents and their relative coordinate spaces

    Medium_Aevum

      Hi,

       

      I'm trying to group-select several UIComponents, then drag one of them and have them all follow the dragger as a group. A typical UI interaction that is very common in any software. So, the question is how can this be done in Flex AS3?

       

      Because startDrag() will only work with one object at a time, dragging several objects simultaneously is not possible. Two options come up as alternatives. One is to periodically update every object with the dragger's coordinates onEnterFrame, for example. This is not ideal because offsets have to be created between each object and the dragger and it just seems cumbersome. The second option, and this is the one that appeals to me more, is grouping the objects to the dragger, that is reparenting them to the dragger on mouseDown event and then un-parenting (and thus reparenting to the original, pre-drag, parents) onMouseUp.

       

      This seems to work when all the objects share the same parent, but when some object get un-parented from a different UIComponent than the dragger's parent and that is not on x:0, y:0, then all sorts of anomalies happen. Objects jump to different locations upon drag.

       

      Has anyone tried to do anything like this before and has run into the same problem? I'l like to avoid rediscovering the wheel if possible, and considering how common a request like this seems to be in today's software parlance, I'd figure I'd ask the forum.

       

      Thanks in advance,

       

      medium_aevum