0
我目前正在編程一種點&點擊AS3中的遊戲與Adobe Flash CS5。當光標改變時點擊不被識別
每當我點擊一扇門時,我想檢查一下是否按住了鑰匙以解鎖它。當從清單中選擇鍵時,我想要光標(不是原始光標,但是與startDrag鏈接的特定光標)獲取該鍵的圖標。
這裏是我的代碼:
var selectedKey:Boolean = false;
key_obj.addEventListener(Mouse.CLICK, selectKey);
door.addEventListener(Mouse.CLICK, openDoor);
inventory_spot.addEventListener(Mouse.CLICK, drop);//send back key to inventory
function selectKey(e:MouseEvent):void
{
cursor.stopDrag();
removeChild(cursor); //disable the old cursor style
key_obj.removeEventListener(Mouse.CLICK, selectKey);
key_obj.startDrag(true);
selectedKey = true;
addChild(inventory_spot);
}
function openDoor(e:MouseEvent):void
{
if (selectedKey)
// open the door
else
// error : you don't have the key
}
function drop(e:MouseEvent):void
{
key_obj.stopDrag();
key_obj.addEventListener(Mouse.CLICK, selectKey);
selectedKey = false;
addChild(cursor); // enable the old cursor
cursor.startDrag(true);
key_obj.x = inventory_spot.x [...] // position of the key in the inventory
key_obj.y = inventory_spot.y [...]
removeChild(inventory_spot);
}
這裏是我的問題:當我門上的鑰匙光標點擊,實際上該計劃甚至不叫openDoor()
什麼也沒有發生,但一旦我放棄關鍵回到庫存,並得到舊的光標,然後openDoor()
工作得很好。
我不明白,函數不是因爲我改變了光標而被調用的?
感謝您的幫助
你說得對,mouseEnabled = false解決了一切。我的key_obj光標的註冊點是movieClip的中心,也許這就是爲什麼每次點擊都是按鍵的原因,而我的其他自定義箭頭狀光標沒有出現該問題?無論如何,問題解決了,謝謝 – 2014-08-28 17:16:41