2011-04-06 43 views
0

我正在使用图像作为光标的应用程序。现在我想知道光标在哪个对象上徘徊。有点像HitTestObject(*),然后我可以看到*代表什么对象。有没有人有任何想法我可以做到这一点? (并且使用鼠标不是选项)AS3:HitTest任何对象

+0

你是否真的需要用图像本身进行测试?鼠标仍然在那里,你只是看不到它。你可以测试/ mouseOver与该 – divillysausages 2011-04-06 14:39:16

+0

鼠标不存在,这就是问题所在;)我使用不同的方法来控制图像:) – 2011-04-06 14:53:34

+0

你是如何控制光标? – divillysausages 2011-04-06 15:09:42

回答

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