# How to drag in a triangle?

**URL:** <https://forum.kirupa.com/t/how-to-drag-in-a-triangle/43069>\
**Category:** Uncategorized\
**Created:** [February 18, 2004, 2:38pm UTC](https://forum.kirupa.com/t/how-to-drag-in-a-triangle/43069 "2004-02-18T14:38:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerartje](https://avatars.discourse-cdn.com/v4/letter/g/e19adc/32.png) [@gerartje](https://forum.kirupa.com/u/gerartje)\
**Post date:** [February 18, 2004, 2:38pm UTC](https://forum.kirupa.com/t/how-to-drag-in-a-triangle/43069/1 "2004-02-18T14:38:39Z")

</div>

Hello,

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

tnx

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 18, 2004, 3:23pm UTC](https://forum.kirupa.com/t/how-to-drag-in-a-triangle/43069/2 "2004-02-18T15:23:20Z")

</div>

Welcome to kirupaForum, gerartje! 🙂

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. 😛

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

```auto
//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. 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 18, 2004, 3:30pm UTC](https://forum.kirupa.com/t/how-to-drag-in-a-triangle/43069/3 "2004-02-18T15:30:58Z")

</div>

tnx mate!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 18, 2004, 3:32pm UTC](https://forum.kirupa.com/t/how-to-drag-in-a-triangle/43069/4 "2004-02-18T15:32:42Z")

</div>

Sure - No problem. 🙂
