dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] hitTest with multiple movieclips

  1. #1
    Junior Member
    Join Date
    Apr 2001
    Posts
    25

    [F8] hitTest with multiple movieclips

    Hello im working on a project where users can drag objects around the screen. I use the xmouse and ymouse to update the objects position when they are dragging the object.

    The problem I am having is when 2 movieclips overlap each other when you click somewhere where they share the same point, both movieclips are dragged. I am trying to get it so only the top movieclip is dragged. I have it swapdepths to the clicked movieclip but it still drags both.

    Code:
    onClipEvent (mouseDown) {
    	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    		_parent.swapIt(this);
    		dragging = true;
    		xOffset = this._x - _root._xmouse;
    		yOffset = this._y - _root._ymouse;
    	}
    }
    onClipEvent (enterFrame)
    {
    	if (dragging) {
    		setProperty("", _x, _root._xmouse + xOffset);
    		setProperty("", _y, _root._ymouse + yOffset);
    	}
    }
    onClipEvent (mouseUp) {
    	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    		dragging = false;
    	}
    }
    swapIt changes the depth to be the highest. This successfully works just it drags both. How can I make it so it will only hit test and drag only the movieclip with the higest depth.

  2. #2
    Working On An Online RPG grimm 88's Avatar
    Join Date
    Sep 2007
    Location
    Nowhere
    Posts
    280
    well just check the depths of both objects colliding with the mouse (store the values in variables or something) and then make it only affect the one with X depth (and X can be dynamically set when you check the depths of both) with something like:
    Code:
    if (depth1 > depth2) {
    x = depth1;
    }
    else if (depth1 < depth2) {
    x = depth2;
    }

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    16
    Or use 'onpress' which does the hitTest and depth checks for you

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