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

Tutorials for drag and drop multiple objects on a sigle target

Community Beginner ,
Jun 20, 2012 Jun 20, 2012

Copy link to clipboard

Copied

I hoping someone could direct me to tutorials that show how to make drag and drop multiple objects to a single target and get different results based on which object I drag.  

TOPICS
ActionScript

Views

3.4K

Translate

Translate

Report

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 ,
Jun 20, 2012 Jun 20, 2012

Copy link to clipboard

Copied

use any drag-and-drop as3 tutorial that you can understand.  in the mouseup listener function your can use the event's currentTarget to determine which object was dropped and then execute the corresponding code.

Votes

Translate

Translate

Report

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 Beginner ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

I found a drag and drop tutorial and I have three movie clips and one target, but I'm not sure how to and the correct script to the mouseup listener function. For instance once one of the objects is dropped I want to go to a new frame. I copied my code below.

var hitArray:Array = new Array(hitTarget1,hitTarget1,hitTarget1);

var dropArray:Array = new Array(drop1,drop2,drop3);

var positionsArray:Array = new Array();

for (var i:int = 0; i < dropArray.length; i++) {

dropArray.buttonMode = true;

dropArray.addEventListener(MouseEvent.MOUSE_DOWN, mdown);

dropArray.addEventListener(MouseEvent.MOUSE_UP, mUp);

positionsArray.push({xPos:dropArray.x, yPos:dropArray.y});

}

function mdown(e:MouseEvent):void {

e.currentTarget.startDrag();

setChildIndex(MovieClip(e.currentTarget), numChildren - 1);

}

function mUp(e:MouseEvent):void {

var dropIndex:int = dropArray.indexOf(e.currentTarget);

var target:MovieClip = e.currentTarget as MovieClip;

target.stopDrag();

if (target.hitTestObject(hitArray[dropIndex])) {

target.x = hitArray[dropIndex].x;

target.y = hitArray[dropIndex].y;

}else{

target.x = positionsArray[dropIndex].xPos;

target.y = positionsArray[dropIndex].yPos;

}

}

Votes

Translate

Translate

Report

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

var hitArray:Array = new Array(hitTarget1,hitTarget1,hitTarget1);

var dropArray:Array = new Array(drop1,drop2,drop3);

var positionsArray:Array = new Array();

for (var i:int = 0; i < dropArray.length; i++) {

dropArray.buttonMode = true;

dropArray.addEventListener(MouseEvent.MOUSE_DOWN, mdown);

dropArray.addEventListener(MouseEvent.MOUSE_UP, mUp);

positionsArray.push({xPos:dropArray.x, yPos:dropArray.y});

}

function mdown(e:MouseEvent):void {

e.currentTarget.startDrag();

setChildIndex(MovieClip(e.currentTarget), numChildren - 1);

}

function mUp(e:MouseEvent):void {

var dropIndex:int = dropArray.indexOf(e.currentTarget);

var target:MovieClip = e.currentTarget as MovieClip;

target.stopDrag();

if (target.hitTestObject(hitArray[dropIndex])) {

target.x = hitArray[dropIndex].x;

target.y = hitArray[dropIndex].y;

if(dropIndex==0){

somemovieclip.gotoAndStop(someframe);

} else if(dropIndex==1){

somemovieclip.gotoAndStop(someotherframe);

} else {

somemovieclip.gotoAndStop(anotherframe);

}

}else{

target.x = positionsArray[dropIndex].xPos;

target.y = positionsArray[dropIndex].yPos;

}

}

Votes

Translate

Translate

Report

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 Beginner ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

Thanks for your feedback thus far. I included my movie clips and go and stop frames. Is what I have below correct.

stop();

var hitArray:Array = new Array(hitTarget1,hitTarget1,hitTarget1);

var dropArray:Array = new Array(drop1,drop2,drop3);

var positionsArray:Array = new Array();

for (var i:int = 0; i < dropArray.length; i++) {

dropArray.buttonMode = true;

dropArray.addEventListener(MouseEvent.MOUSE_DOWN, mdown);

dropArray.addEventListener(MouseEvent.MOUSE_UP, mUp);

positionsArray.push({xPos:dropArray.x, yPos:dropArray.y});

}

function mdown(e:MouseEvent):void {

e.currentTarget.startDrag();

setChildIndex(MovieClip(e.currentTarget), numChildren - 1);

}

function mUp(e:MouseEvent):void {

var dropIndex:int = dropArray.indexOf(e.currentTarget);

var target:MovieClip = e.currentTarget as MovieClip;

target.stopDrag();

if (target.hitTestObject(hitArray[dropIndex])) {

target.x = hitArray[dropIndex].x;

target.y = hitArray[dropIndex].y;

if(dropIndex==0){

drop1.gotoAndStop(2);

} else if(dropIndex==1){

drop2.gotoAndStop(3);

} else {

drop3.gotoAndStop(4);

}

}else{

target.x = positionsArray[dropIndex].xPos;

target.y = positionsArray[dropIndex].yPos;

}

}

Votes

Translate

Translate

Report

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

it's possible that's correct but noone could determine that from the information you've given.  you should be able to see how your app is performing and determine if that is what you want.

Votes

Translate

Translate

Report

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 Beginner ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

I inserted a new frame and placed text on the layer, but when I drop the movie clips on the target, it doesn't jump to the new frame with the text added, just the drag and drop function works. Do you think it would help if you could view the actual FLA, Is there anywhere I can upload it, or is this just a hopeless cause.

Votes

Translate

Translate

Report

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

LATEST

use the trace function to debug your actionscript:

function mUp(e:MouseEvent):void {

var dropIndex:int = dropArray.indexOf(e.currentTarget);

var target:MovieClip = e.currentTarget as MovieClip;

target.stopDrag();

if (target.hitTestObject(hitArray[dropIndex])) {

target.x = hitArray[dropIndex].x;

target.y = hitArray[dropIndex].y;

trace(dropIndex);

// if this traces something other than -1, put trace functions in frame 2 of drop1, frame 3 of drop2 etc.

if(dropIndex==0){

drop1.gotoAndStop(2);

} else if(dropIndex==1){

drop2.gotoAndStop(3);

} else {

drop3.gotoAndStop(4);

}

}else{

target.x = positionsArray[dropIndex].xPos;

target.y = positionsArray[dropIndex].yPos;

}

}

Votes

Translate

Translate

Report

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