我正在开发一个图像作为光标的应用程序。现在我想随时知道光标悬停在哪个对象上。有点像 HitTestObject(*),然后我可以看到 * 代表什么对象。有谁知道我怎么能做到这一点?(并且不能使用鼠标)
问问题
5982 次
2 回答
1
将要监视“悬停”的元素放在单独的数组中,然后将 onEnterFrame 侦听器添加到附加到鼠标的对象上,该对象遍历数组并对每个对象执行 hitTests。
var hitTestClips:Array;
// populate hitTestClips with the items you want to hitTest
这将进入鼠标附加对象的 onEnterFrame 处理程序:
for(var item:MovieClip in hitTestClips)
{
if(item.hitTest(this.x, this.y, true))
{
trace('now hovering above ' + item);
}
}
于 2011-04-06T14:19:06.190 回答
1
我已经解决了这个问题:) 因为光标与其他光标位于不同的精灵中,所以我必须这样做,因为我无法将对象传递到悬停到数组中。
//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);
}
于 2011-04-06T14:49:13.307 回答