I am working on an application where an image serves as cursor. Now i would like to know at any time over which object the cursor is hovering. Sort of like a HitTestObject(*) where i can then see what object the * represents. Does anyone have any idea how i could accomplish this? (and using the mouse is not an option)
Asked
Active
Viewed 6,013 times
0
-
Do you really need to hittest with the image itself? The mouse is still there, you just can't see it. You can hittest/mouseOver with that – divillysausages Apr 06 '11 at 14:39
-
the mouse isn't there, that is what the problem is ;) i am using a different method to control the image :) – Michiel Standaert Apr 06 '11 at 14:53
-
how are you controlling the cursor? – divillysausages Apr 06 '11 at 15:09
-
haha, ok then :D. I see you fixed it anyway, so good luck! – divillysausages Apr 06 '11 at 15:39
2 Answers
1
Put the elements you want to monitor for 'hovering' in a separate array, then add an onEnterFrame listener to the object attached to your mouse that iterates through the array and performs hitTests with each of the objects.
var hitTestClips:Array;
// populate hitTestClips with the items you want to hitTest
and this goes in the onEnterFrame handler for your mouse-attached object:
for(var item:MovieClip in hitTestClips)
{
if(item.hitTest(this.x, this.y, true))
{
trace('now hovering above ' + item);
}
}

Timothy Groote
- 8,614
- 26
- 52
-
i tried that before, but couldn't use it because some objects weren't children of the cursor :) thanks anyway – Michiel Standaert Apr 06 '11 at 15:01
1
I have solved the problem already :) since the cursor was in a different sprite than the others, i had to do it this way, because i couldn't pass the objects to hover into an array.
//First we will create a point that contains the x and y of this cursor.
var _position:Point = new Point(x + (width/2), y + (height/2));
//Secondly, we will get an array of elements that are under this point.
var _objects:Array = parentApplication.getObjectsUnderPoint(_position);
//If the length of the objectsList is longer than or equal to 2, we may assume that
//there is an object
if(_objects.length >= 2)
{
//Set the currentObject variable to the object the cursor is hovering over.
//The minus two is simple. The cursor is always the last object under that point,
//so we need the object before that.
_currentObject = _objects[_objects.length - 2];
//dispatch the event in the object.
dispatchCursorEventToObject(EyeEvent.CURSOROVER);
}

Michiel Standaert
- 4,096
- 7
- 27
- 49