A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Drag and Drop Hit-test

Hybrid View

  1. #1
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    hello,

    i havent got too much time at the moment to make you a taylor made function, but i do have a script which will help you.

    it is just one function, and you can have any clip being the target or the one thats being dragged. im my example the dragged clip changes alpha when it is in close proximity to the target:
    Code:
    function dragAndDrop(clip:MovieClip, target:MovieClip, range:Number):Void {
            var dragging:Boolean = false;
            clip.onPress = function() {
                    this.swapDepths(this.getNextHighestDepth());
                    this.startDrag(false);
                    dragging = true;
            };
            clip.onRelease = clip.onReleaseOutside=function () {
                    this.stopDrag();
                    dragging = false;
            };
            var orX:Number = clip._x;
            var orY:Number = clip._y;
            clip.onMouseMove = function() {
                    if (!dragging) {
                            if (Math.round(Math.sqrt(Math.pow(clip._x-target._x, 2)+Math.pow(clip._y-target._y, 2)))<=range) {
                                    clip._x = target._x;
                                    clip._y = target._y;
                            } else {
                                    clip._x = orX;
                                    clip._y = orY;
                            }
                            clip._alpha = 100;
                    } else if (dragging) {
                            if (Math.round(Math.sqrt(Math.pow(clip._x-target._x, 2)+Math.pow(clip._y-target._y, 2)))<=range) {
                                    clip._alpha = 60;
                            } else {
                                    clip._alpha = 100;
                            }
                    }
                    updateAfterEvent();
            };
    }
    // USAGE
    //dragAndDrop(clip, clipTarget, myRange)
    just put the code on the frame,

    the first parameter is the clip which you want to drag, the second parameter is the clip you want as the target, and the third is how close you want the clip to be to the target, so that when it is released it goes to the target.

    this method is based on distance checking and not hittest or onRollOver/Out.

    HTH,

    zlatan
    New sig soon

  2. #2
    bCPro
    Join Date
    Jun 2006
    Location
    flashLand
    Posts
    5
    Hi Dudeqwerty!!

    thanks a lot for your reply, appreciate it!!!

    But I'm not too sure if it is the code that I need.

    Let me tell you what I want to achieve and maybe you can give me a tip.

    I'm doing a website for an interior designer, I have multiple drag & drop objects to decorate a room.

    1- I need to duplicate the first object that the user drags just incase it is used again.
    2- I need to be able to apply colours and patterns to all duplicates.
    3- The example I'm using is based on frame labels which means to me that I need to have as many frame labels as combination of colours and patterns (quit a lot!!)

    I post the file just incase you want to have a look.

    Thanks in advance...
    Attached Files Attached Files

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