mercredi 1 mars 2017

How to create a drag/drop with ActionScript 3.0? Multiple items being dragged to multiple targets

I am creating an interactive paper doll in Adobe Animate and am having some trouble making the drag drop feature work. I have multiple clothing items that will need to have the possibility of being dragged to the same area. For example I may have 4 different shirt options. I have started with the two dresses (yellow dress_mc & blue dress_mc). The yellow dress is working properly, but the blue dress won't work, I can drag it, but not drop it. Any suggestions?

This is the code I have right now:

var objectoriginalX:Number;
var objectoriginalY:Number;

flower_mc.buttonMode = true;
flower_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
flower_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

yellowdress_mc.buttonMode = true;
yellowdress_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
yellowdress_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

bluedress_mc.buttonMode = true;
bluedress_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
bluedress_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

function pickupObject(event:MouseEvent):void {;;
objectoriginalX =;
objectoriginalY =;
function dropObject(event:MouseEvent):void {;
var matchingTargetName:String = "target" +;
var matchingTarget:DisplayObject = getChildByName(matchingTargetName);
if ( != null && == 
matchingTarget){, pickupObject);, dropObject); = false; = matchingTarget.x; = matchingTarget.y;
} else { = objectoriginalX; = objectoriginalY;

Aucun commentaire:

Enregistrer un commentaire