How can I drop to any target from this code?
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How can I drop to any target from this code?

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    2

    How can I drop to any target from this code?

    I want to drag square, circle and triagle and drop to any target. What code should be added? Please help.

    import flash.events.MouseEvent;
    import flash.display.MovieClip;

    var dragArray:Array = [square, circle, triangle];
    var matchArray:Array = [squareMatch, circleMatch, triangleMatch];

    var currentClip:MovieClip;
    var startX:Number;
    var startY:Number;

    for(var i:int = 0; i < dragArray.length; i++) {
    dragArray.buttonMode = true;
    dragArray.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
    matchArray.alpha = 0.2;
    }

    function item_onMouseDown(event:MouseEvent):void {
    currentClip = MovieClip(event.currentTarget);
    startX = currentClip.x;
    startY = currentClip.y;
    addChild(currentClip); //bring to the front
    currentClip.startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    }

    function stage_onMouseUp(event:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    currentClip.stopDrag();
    var index:int = dragArray.indexOf(currentClip);
    var matchClip:MovieClip = MovieClip(matchArray[index]);
    if(matchClip.hitTestPoint(currentClip.x, currentClip.y, true)) {
    //a match was made! position the clip on the matching clip:
    currentClip.x = matchClip.x;
    currentClip.y = matchClip.y;
    //make it not draggable anymore:
    currentClip.removeEventListener(MouseEvent.MOUSE_D OWN, item_onMouseDown);
    currentClip.buttonMode = false;
    } else {
    //match was not made, so send the clip back where it started:
    currentClip.x = startX;
    currentClip.y = startY;
    }
    }

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,093
    Can you post your fla?

    Is it a problem with hitTestPoint?

    You can put whatever shapes in identical clips - use a clear button or clear background 200x200 over the shape for example - then just test for matching x,y of the clips. You wouldn't need to use collision detection.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Can you post your fla?

    You can put whatever shapes in identical clips - use a clear button or clear background 200x200 over the shape for example - then just test for matching x,y of the clips. You wouldn't need to use collision detection.
    Here is my fla. Please show me how.

    https://www.dropbox.com/s/sy39fo7k6r...any_target.fla
    Last edited by noppanat; 11-24-2013 at 07:48 PM.

Posting Permissions

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




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com