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

multiple "drag and drop"

New Here ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

HI, i have a problem with drag and drop programming in animate actionscript 3

i have 2 movieclips "red1" and "red2"

and the goal is to drag any of them to the targerts "target1" and "target2" that

the specific drag of the movieclip to its target does not matter (red 1 can be dragged to target2, and vice versa)

how do i do that?

thank you!

Views

220

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

correct answers 1 Correct answer

Community Expert , Sep 20, 2018 Sep 20, 2018

as mentioned in message 1, you should be using currentTarget instead of target.

once your do that, what's the problem?

Votes

Translate

Translate
Community Expert ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

add mousedown and mouseup listeners to both

in the mousedown listener start a loop that assigns the currentTarget's x and y properties to mouseX and mouseY.

in the mouse up listener terminate the loop and check for a hit with your drop target.

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
New Here ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

kglad yes that part i understood, i have sucsessfully created drag and drop with one object and one target (when object dropped on target, it stays, and when object dropped anywhere else, it returns to original position)

now i try to do the same with 2 identical objects, and 2 targets, and for my purpose it shouldn't matter what object i drag to what target, when i drag the object to any target, it should stay there, and then drag the second object to the remaining target.

thank you

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 ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

what's the problem?

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
New Here ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

kglad, I do not know how to make the drag and drop with 2 objects & targets, only with single object and drop target.

when its object -------> target, its fine.

when its object 1 and object 2 --------> target 1 and 2, it doesnt works.

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 ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

show your 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
New Here ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

var objectoriginalX:Number;

var objectoriginalY:Number;

function startdragging (event:MouseEvent):void

{

event.target.startDrag();

event.target.parent.addChild(event.target);

//trace(event.target.parent);

objectoriginalX = event.target.x;

    objectoriginalY = event.target.y;

}

function stopdragging (event:MouseEvent):void

{

event.target.stopDrag();

var droptargetname:String = "target" + event.target.name;

var droptarget:DisplayObject = getChildByName(droptargetname);

var targetcenter:Number;

var droptargetcenter:Number;

targetcenter = (event.target.x + event.target.width) / 2;

droptargetcenter = (droptarget.x + droptarget.width) / 2;

if ((event.target.dropTarget != null) && (event.target.dropTarget.parent == droptarget))

{

//trace(event.target.dropTarget.parent.x);

event.target.removeEventListener(MouseEvent.MOUSE_DOWN, startdragging);

        event.target.removeEventListener(MouseEvent.MOUSE_UP, stopdragging);

event.target.x = droptarget.x

event.target.y = droptarget.y

}

else

{

    event.target.x = objectoriginalX;

    event.target.y = objectoriginalY;

}

}

red.addEventListener(MouseEvent.MOUSE_DOWN, startdragging);

red.addEventListener(MouseEvent.MOUSE_UP, stopdragging);

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
New Here ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

i put it in the comment above.

it works perfectly fine with 1 object and target, now i try to make it with 2

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 ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

LATEST

as mentioned in message 1, you should be using currentTarget instead of target.

once your do that, what's the problem?

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