我有對象,他們顯示鼠標在他們身上的文本。我爲此使用了MOUSE_MOVE事件。問題是當鼠標離開物體時,文本停留在最後的位置。我希望它消失,直到鼠標再次觸摸對象。怎麼做?如何讓鼠標不在物體上時文字消失?
這是我編輯的代碼。我發現MOUSE_OUT或ROLL_OUT工作得很好。現在唯一的問題是,當我在對象和文本上顯示時,當我將鼠標移動到文本上足夠快時,它會閃爍。我認爲這是因爲文本覆蓋了對象,當我在文本上時,我不再是對象。所以我只是將文本從光標移開一點。感謝您的回答:)
import flash.events.MouseEvent;
import inventory.inventorySystem;
import inventory.item;
import flash.text.TextField;
var IS:inventorySystem;
var IT:item;
apple.itemName = "Apple";
apple.itemIcon = new AppleIcon();
apple.addEventListener(MouseEvent.MOUSE_MOVE, showItemNameF);
apple.addEventListener(MouseEvent.MOUSE_OUT, hideItemNameF);
pear.itemName = "Pear";
pear.itemIcon = new PearIcon();
pear.addEventListener(MouseEvent.MOUSE_MOVE, showItemNameF);
pear.addEventListener(MouseEvent.MOUSE_OUT, hideItemNameF);
function showItemNameF(e:MouseEvent):void{
var itemNameBox:String;
itemNameBox = item(e.currentTarget).itemName;
stage.addChild(infoBoxObject);
infoBoxObject.infoBox.text = itemNameBox;
infoBoxObject.x = mouseX;
infoBoxObject.y = mouseY;
}
function hideItemNameF(e:MouseEvent):void{
infoBoxObject.x = -145;
infoBoxObject.y = 61;
}
@AnilDemir - 如果有效 - 請接受答案或讓我們知道您是否需要更多信息。 –