Copy link to clipboard
Copied
So I've been sitting down for the past few hours trying to search the web for solutions about being able to drag and drop one MovieClip between multiple Targets. I have no idea and I am struggling to find anything that will help me with this. This is for a drag and drop class assignment and I would please like some help, if I may. Here's the general outline.
The scene is a multiple-choice quiz. There are 3 statements lined up next to 3 boxes, these are my Targets. One movieclip appears in the corner, this is the item I wish to enable dragging and dropping into any of the 3 Targets. These targets are named seperately as target1_mc, target2_mc, and target3_mc. The movieclip that is the "selector" for the multiple-choice is named selector_mc.
I only know the basic drag and drop script that was taught in class but that is only for a single target, not 3. An image has been provided below. To reiterate, selector_mc is the blue square in the uppermost part of the screen. Targets (target1_mc, target2_mc, target3_mc) are on the rightmost part of the screen. I want to let that blue square be able to be dragged and dropped onto the target areas and snap to any of them, invoking a response to it.
selector_mc.origX = selector_mc._x;
selector_mc.origY = selector_mc._y;
selector_mc.onPress=function(){
this.startDrag();
}
selector_mc.onRelease=function(){
this.stopDrag();
if(eval(this._droptarget)==target1_mc){
// do something. red dragon was selected
this._x = target1_mc._x;
this._y = target1_mc._y;
} else
if(eval(this._droptarget)==target2_mc){
// do something. white dragon was selected
this._x = target2_mc._x;
this._y = target2_mc._y;
} else
if(eval(this._droptarget)==target3_mc){
// do something.blackdr
...Copy link to clipboard
Copied
selector_mc.origX = selector_mc._x;
selector_mc.origY = selector_mc._y;
selector_mc.onPress=function(){
this.startDrag();
}
selector_mc.onRelease=function(){
this.stopDrag();
if(eval(this._droptarget)==target1_mc){
// do something. red dragon was selected
this._x = target1_mc._x;
this._y = target1_mc._y;
} else
if(eval(this._droptarget)==target2_mc){
// do something. white dragon was selected
this._x = target2_mc._x;
this._y = target2_mc._y;
} else
if(eval(this._droptarget)==target3_mc){
// do something.blackdragon was selected
this._x = target3_mc._x;
this._y = target3_mc._y;
} else {
// missed em all
this._x = this.origX;
this._y = this.origY;
}
}
Copy link to clipboard
Copied
Adding this to the movie clip instance seems to bring up issues about the if statements not being in an 'on/onClipEvent' handler. Adding it onto the frame just makes the movie clip draggable but it doesn't snap to any of the targets and it doesn't snap back to it's original position.
Copy link to clipboard
Copied
no code should be attached to objects. attach that code to the first frame that contains those objects.
Copy link to clipboard
Copied
Doesn't seem to be working for me, My objects appear on different frames from each other instead of the single frame.. They have tweens between them so that they have a "grow" transition. Do they all have to start on the same frame?
Copy link to clipboard
Copied
add a keyframe in each layer so all those objects referenced in code are correctly defined in the frame in which the code executes.
Copy link to clipboard
Copied
Thank you so much! You're a lifesaver!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now