开发者

multiple draggable item into a single target AS3

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

I'm 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜