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