How to drag in a triangle?

Hello,

i want to drag my object, but the boundaries have to form a triangle and not the standard rectangle…
Is this possible??

tnx

Welcome to kirupaForum, gerartje! :slight_smile:

I guess that the easiest way would be drawing the shape of the triangle, converting it into a movie clip symbol, and then use the [font=courier new]MovieClip.hitTest()[/font] method to check if the location of the mouse if within the triangle’s area. :stuck_out_tongue:

Here’s a quick example (just paste the code on the frame actions of the movie):

//draw a big triangle
this.createEmptyMovieClip("triangle", 0);
triangle.beginFill(0xCC0000, 100);
triangle.moveTo(100, 0);
triangle.lineTo(200, 200);
triangle.lineTo(0, 200);
triangle.lineTo(100, 0);
triangle.endFill();
//now draw a little circle to drag around
this.createEmptyMovieClip("circle", 1);
circle.lineStyle(10, 0x000000, 100);
circle.lineTo(0.15, 0);
//put the circle within the triangle
circle._x = 100;
circle._y = 100;
//start dragging the circle when it's pressed
circle.onPress = function() {
//update the position everytime the mouse is moved
this.onMouseMove = function() {
//get the location of the mouse
var x = this._parent._xmouse;
var y = this._parent._ymouse;
//check if the location is within the triangle
if (triangle.hitTest(x, y, true)) {
//move the circle
this._x = x;
this._y = y;
}
//refresh the movie
updateAfterEvent();
};
};
//stop dragging the circle when it's released
circle.onRelease = function() {
delete this.onMouseMove;
};
circle.onReleaseOutside = circle.onRelease;

Simple, yet effective! Plus, this method is not limited to a triangular area, you can use it for any shape you want!

…Let me know if you have any questions. :wink:

tnx mate!!

Sure - No problem. :slight_smile: