我正在使用圖像作爲光標的應用程序。現在我想知道光標在哪個對象上徘徊。有點像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