2013-12-12 44 views
0

我有對象,他們顯示鼠標在他們身上的文本。我爲此使用了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; 
} 

回答

0

只需將Enabled設置爲false,並且MouseOver-Event啓用true即可。

0

如果您使用的是MOUSE_MOVE事件,請注意此事件在移動鼠標時會不斷閃爍。如果您在此事件中執行了大量邏輯,則在某些情況下會導致您的應用程序變慢。 (只是一個便箋)

如果你使用的是MOUSE_MOVE,你可以使用hitTestObject()來檢查你是否在觸摸文本容器(在這裏有很多關於如何實現這個的例子) )。

最好是在文本的容器上使用鼠標輸入和鼠標離開事件。

如需更多幫助,您需要給我們一些代碼示例。

+0

@AnilDemir - 如果有效 - 請接受答案或讓我們知道您是否需要更多信息。 –