我正在使用图像作为光标的应用程序。现在我想知道光标在哪个对象上徘徊。有点像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障碍hitTest
- 3. AS3 Custom HitTest
- 4. hittest,removechild,不可见对象保持问题,闪存,as3
- 5. 使用数组和hitTest - AS3
- 6. AS2到AS3 hitTest迁移
- 7. 忽略的对象则hitTest
- 8. 如何从HitTest获取对象类型?
- 9. hitTest与阵列相同的数组AS3
- 10. 带有Illustrator路径的AS3 Hittest
- 11. Swift中的SceneKit HitTest小对象
- 12. hitTest与两个数组中的对象
- 13. AS3类对象?
- 14. AS3对象运动
- 15. AS3 - 回收对象
- 16. AS3定心对象
- 17. AS3 - 删除对象
- 18. as3对象值NativeText
- 19. AS3对象过滤
- 20. AS3 with(){} - 以任何方式引用()中的对象?
- 21. 任何对象
- 22. AS3如何在hittest后添加秒(游戏)定时器?
- 23. 如何在bitmapData和对象之间正确使用hitTest?
- 24. AS3对象序列化(至AS3代码)
- 25. AS3 - 使对象模糊特定对象
- 26. 测试反对则hitTest对象数组的值
- 27. 做任何==对象
- 28. AS3:更改对象的值
- 29. AS3对象旋转问题
- 30. AS3对象数组到类
你是否真的需要用图像本身进行测试?鼠标仍然在那里,你只是看不到它。你可以测试/ mouseOver与该 – divillysausages 2011-04-06 14:39:16
鼠标不存在,这就是问题所在;)我使用不同的方法来控制图像:) – 2011-04-06 14:53:34
你是如何控制光标? – divillysausages 2011-04-06 15:09:42