Skip navigation
lightwavemac
Currently Being Moderated

Tutorials for drag and drop multiple objects on a sigle target

Jun 20, 2012 12:36 PM

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.  

 
Replies
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 20, 2012 1:25 PM   in reply to lightwavemac

    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.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 21, 2012 9:11 AM   in reply to lightwavemac

     

     

     

    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[i].buttonMode = true;

    dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);

    dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);

     

     

    positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].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;

    }

    }

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 21, 2012 1:10 PM   in reply to lightwavemac

    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.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 21, 2012 4:39 PM   in reply to lightwavemac

    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;

    }

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points