views:

46

answers:

1

Hi,

Im new to AS3 and was wondering if there is anyone out there that can help me with this...

Im creating a drag and drop Flash activity where there is 1 target and multiple draggable items. In my case I have 4 apples and I want to be able to put all apples into the same basket. I can get the draggable item into one target but i cannot get multiple draggable items into one single target...

Here is my code...


import caurina.transitions.*; //import flash.geom.Rectangle;

//var myBoundaries:Rectangle=new Rectangle(68.65,637.8,100,50);

circle1_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag); circle1_mc.addEventListener(MouseEvent.MOUSE_UP, drop);

function drag(event:MouseEvent):void { //event.target.startDrag(true, myBoundaries); event.target.startDrag(); }

function drop(event:MouseEvent):void { event.target.stopDrag(); var myTargetName:String = "target" + event.target.name; var myTarget:DisplayObject = getChildByName(myTargetName); if(event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){ //trace("hit");

    /*Remove the event listeners when a peg is correctly placed*/
    event.target.removeEventListener(MouseEvent.MOUSE_DOWN, drag);
    event.target.removeEventListener(MouseEvent.MOUSE_UP, drop);
    event.target.buttonMode = false;

    /*Adjust the peg’s position when it is correctly placed*/
    event.target.x = myTarget.x;
    event.target.y = myTarget.y;

    /*add tween*/
    Tweener.addTween(circle1_mc,{x:68.65,y:637.8,time:1,transition:"easeIn"});
} else {
    //trace("try again");

    /*add tween*/
    Tweener.addTween(circle1_mc,{x:97.9,y:64.95,time:1,transition:"easeIn"});
}

}

circle1_mc.buttonMode = true;


Hope to hear from you soon

A: 

Perhaps wrapping the apples in to an appleContainer ( draggableItemContainer? ) then instead of dragging single apples you'll be able to focus on the appleContainer as your target?

Karl Freeman
Hi Karl, Thanks for your help on this... they all have to be separate items, for example, all red fruit in one basket, green in the other and other colours in the 3rd
Sapan Sidher
In that case perhaps when a user selected ( MouseEvent.MOUSE_DOWN ) has mouse downed the object. You take the object and find its peers in the container and do the startDrag on only thoose objects. Or, Wrap up all the apples in to an appleContainer, then wrap each type of apple in to greenApples. Then you can apply the same logic as if you were be dragging one instance?
Karl Freeman
Karl is right.. Make three arrays or as required. RedApples , GreenApples and so on.. On MouseEvent.MOUSE_DOWN handler check if(evt.target.name==RedApples[0].name) then drag All red apples. else check for green and so on.. But you have to keep the name same for all one color apples.
Muhammad Irfan