The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 1 of 1

Thread: AS3 Multiple Drop Targets (Again)

  1. #1

    AS3 Multiple Drop Targets (Again)

    Hi, this question has been asked by someone else using similar code a while ago at http://www.kirupa.com/forum/showthre...ight=drag+drop but I still can't get it to work, so I have simplified my version and attached the source files. (They are based on a tutorial from here).

    It is a word puzzle where I am having trouble getting a letter that is duplicated to drop onto either position (i.e. in the word "EVE" I can get the first "E" to drop on the first target and the last "E" onto the last target, but I don't know how to get either "E" to fall on either the first or second target).

    Can anyone help out?

    The code:

    HTML Code:
    var startX:Number;
    var startY:Number;
    var counter:Number = 0;
    
    E.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
    E.addEventListener(MouseEvent.MOUSE_UP, drop);
    V.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
    V.addEventListener(MouseEvent.MOUSE_UP, drop);
    E2.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
    E2.addEventListener(MouseEvent.MOUSE_UP, drop);
    
    function pickup(event:MouseEvent):void {
        event.target.startDrag(true);
        reply_txt.text = "";
        event.target.parent.addChild(event.target);
        startX = event.target.x;
        startY = event.target.y;
    }
    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){
            reply_txt.text = "Correct!";
            event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickup);
            event.target.removeEventListener(MouseEvent.MOUSE_UP, drop);
            event.target.buttonMode = false;
            event.target.x = myTarget.x;
            event.target.y = myTarget.y;
            counter++;
        } else {
            reply_txt.text = "Try Again!";
            event.target.x = startX;
            event.target.y = startY;
        }
        if(counter == 3){
            reply_txt.text = "Finished!";
            this.play();
        }
    
    }
    
    E.buttonMode = true;
    V.buttonMode = true;
    E2.buttonMode = true;
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012