Nice example! Can't use the "Drag object" in flash though![]()
Nice example! Can't use the "Drag object" in flash though![]()
It's funny that this thread is up right now, because I'm building a level editor and needed a way to group objects so I can drag a box around them to select them and then move them.
But yeah the examples aren't that much help for this because it isn't dynamic. I came up with a solution by just using an array to keep track of the x/y positions of each object I want to move. Basically when you click the mouse down, you should run a fastloop for the number of selected objects and save this to an array:
XMouse - X position of each object being iterated (save fast loop index to X array value)
YMouse - Y position of each object being iterated (just set Y array value to 1)
Also on the click down event, set a flag somewhere to 1 to indicate that dragging is active.
Then have a condition below that checks for the dragging flag to be 1, and while it is true run an opposite fastloop through those objects again but instead of saving to array, you read from it:
- Set x position of iterated object to XMouse - X Array value at current iteration
- Set y position of iterated object to YMouse - X Array value at current iteration and Y at 1
Then on mouse not being held down, set the drag flag to 0 to stop the dragging.
All you are doing is storing all the object x/y positions in relation to the mouse, so it knows where to place them once the mouse starts moving.



Interesting! Really cool ideas! I will put these to the best of use! Thanks so much!![]()
Konidias, be interested in seeing an example of this if you have the time.



@KLiK-iT
Here is the updated example without any extension, should work in Flash now: Drag & Drop Groups 2.mfa
Additional the dragging of a single item is now restricted to the range of the Container box by
1) Find the max. value of X(Item) and Left Edge(Box)
2) Find the min. value of 1) and Right Edge(Box), this is the new X-Position of the object.
The same goes for the Y-Position.
In one line for X and Y:
Set X to Min(Max (X(Item), Left Edge(Box)), Right Edge Box)
Set Y to Min(Max (Y(Item), Top Edge(Box)), Bottom Edge Box)
@Konidias
This example uses a similar solution you suggested, but stores the position values directly in the Alterable Value of the objects.
With the Pick object with fixed value-Condition you can set/read the values and set the position of the objects each one in a single line, a Fastloop is not necessary.
It goes to show how many different ways there are to accomplish the same type outcome in MMF. Nice!
I think I avoided the pick object method because I was using a selection rectangle method and not just putting an active object as a box behind the other objects. Meaning you could drag a selection box over multiple objects and they would then be "selected" you then click drag any one of them to move the entire group. But maybe I was doing something wrong... I might try this other method then, but really in this case a fast loop is not going to harm anything. Maybe if I was having to select and move 1000 objects.



Amazing Quinto! Thanks so much!