|
-
This is just an idea, but if you've got a system where you have a long list of draggable objects and a long list of drop spots, you would create a function that sets it up, and then for the number of drag and drops you have, you just run through that function however many times.
I don't know if it's the best way to go about it (still on the road of learning myself) but what could work is this:
Code:
var dragMovieClips:Array = [drag1, drag2, drag3]; //Array of all drag MovieClips
var dropMovieCilps:Array = [drop1, drop2, drop3]; //Array for all drop MovieClips
//This for loop runs through however many drag and drop objects you have
//(it's based on the number of drag objects, however)
for(var i:int=0; i<dragMovieClips.length; i++){
setUpDrag(dragMovieClips[i], dropMovieCilps[i]); //Run the function that sets up each drag and drop instance
}
//Function that sets up each drag and drop instance
function setUpDrag(dragMc:MovieClip, dropMc:MovieClip):void{
//Put other drag and drop code here
//Such as aComm2.target = selectionPage.courseTarget;
//E.g.
dragMc.target = selectionPage.dropMc;
}
What I'm doing is I have two arrays, once with all the drag MovieClips, and another with all the drop MovieClips. Both arrays are in order as well, so there is a small amount of setting up to make sure nothing stuffs up.
Then I do a for loop for however many MovieClips are in the dragMovieClip array (in this case, it runs 3 times). For each time the loop fires, it sets up a pair of drag and drop items based on the current position of the loop. The variable i in the loop starts at 0, and will finish at 2, so I use this as a way to target each item in both arrays by using it as the index: dragMovieClip[0] returns drag1, so dragMovieClip[i] will return whatever i is equal to.
---
For the other question, when you add a child and want it's coordinates to be that of the mouse, just use mouseX and mouseY:
Code:
ball.x = mouseX;
ball.y = mouseY;
addChild(ball)
Just take note of the ball's registration point as you add it. If you want the ball's centre to be on the mouse when it's added, make sure the registration point of the ball is set to the centre, and not the top left (or anything else).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|