我正在使用图像作为光标的应用程序。现在我想知道光标在哪个对象上徘徊。有点像HitTestObject(*),然后我可以看到*代表什么对象。有没有人有任何想法我可以做到这一点? (并且使用鼠标不是选项)AS3:HitTest任何对象
0
A
回答
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);
}
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);
}
}
+0
我曾尝试过,但无法使用它,因为一些对象不是光标的子项:)谢谢反正 – 2011-04-06 15:01:52
相关问题
- 1. AS3视线不使用hittest对象。
- 2. AS3 Custom HitTest
- 3. 多个hittest AS3
- 4. AS3障碍hitTest
- 5. hittest,removechild,不可见对象保持问题,闪存,as3
- 6. AS3:Hittest无法及时捕获拖动的对象
- 7. AS3 HitTest gotoAndPlay而不是removeChild
- 8. 使用数组和hitTest - AS3
- 9. AS2到AS3 hitTest迁移
- 10. 忽略的对象则hitTest
- 11. 如何从HitTest获取对象类型?
- 12. 带有Illustrator路径的AS3 Hittest
- 13. hitTest与阵列相同的数组AS3
- 14. AS3 - HitTest不能正常工作
- 15. 我的AS3 hitTest应该去哪里?
- 16. Swift中的SceneKit HitTest小对象
- 17. AS3类对象?
- 18. 尽管HitTest对象被删除,但对象仍然消失
- 19. as3对象值NativeText
- 20. AS3对象过滤
- 21. 推对象在AS3
- 22. AS3对象到JSON
- 23. AS3定心对象
- 24. AS3对象运动
- 25. AS3 - 删除对象
- 26. AS3 - 回收对象
- 27. AS3快线对象
- 28. AS3 {} VS新对象
- 29. AS3 with(){} - 以任何方式引用()中的对象?
- 30. 任何对象
你是否真的需要用图像本身进行测试?鼠标仍然在那里,你只是看不到它。你可以测试/ mouseOver与该 – divillysausages 2011-04-06 14:39:16
鼠标不存在,这就是问题所在;)我使用不同的方法来控制图像:) – 2011-04-06 14:53:34
你是如何控制光标? – divillysausages 2011-04-06 15:09:42