Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Single MovieClip Drag and Drop to Multiple Targets

New Here ,
Jul 24, 2013 Jul 24, 2013

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.

Capture.PNG

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 24, 2013 Jul 24, 2013

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

...
Translate
Community Expert ,
Jul 24, 2013 Jul 24, 2013

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;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 24, 2013 Jul 24, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2013 Jul 24, 2013

no code should be attached to objects.  attach that code to the first frame that contains those objects.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 24, 2013 Jul 24, 2013

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?

Untitled.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2013 Jul 24, 2013

add a keyframe in each layer so all those objects referenced in code are correctly defined in the frame in which the code executes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2013 Jul 25, 2013

Thank you so much! You're a lifesaver!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 25, 2013 Jul 25, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines