Actionscript 鼠标悬停动作脚本
我正在用flex设计一个页面,我有一张图片。当用户将鼠标悬停在图像上时,应显示特定文本。这是我写的actionScript代码,但它不起作用(它没有在mouseOver事件()上显示文本)Actionscript 鼠标悬停动作脚本,actionscript,event-handling,onmouseover,Actionscript,Event Handling,Onmouseover,我正在用flex设计一个页面,我有一张图片。当用户将鼠标悬停在图像上时,应显示特定文本。这是我写的actionScript代码,但它不起作用(它没有在mouseOver事件()上显示文本) private var helpText:String=“一些文本。” 私有函数helpiconvent(e:MouseEvent):void{ 如果(e.type==“鼠标悬停”){ e、 currentTarget.helpText.visible=true; } } 专用函数addEve
private var helpText:String=“一些文本。”
私有函数helpiconvent(e:MouseEvent):void{
如果(e.type==“鼠标悬停”){
e、 currentTarget.helpText.visible=true;
}
}
专用函数addEventToHelpIcon():void{
helpIcon.addEventListener(MouseEvent.MOUSE_OVER,helpIconvent);
}
如有任何帮助/见解,将不胜感激
谢谢。它认为您的代码应该更像这样,但我不习惯flex,所以如果我错了,请容忍我
private function foo(e:MouseEvent):void {
if(e.type == MouseEvent.ROLL_OVER)
//Do stuff...
}
有几个问题:
- 您没有正确添加鼠标悬停侦听器。您实际上是在添加两个事件侦听器,一个在MXML中,然后在该事件发生时添加第二个。只需使用MXML侦听器(见下文)
- 在鼠标悬停时运行的函数中,您试图在字符串对象上设置
属性。字符串本身不会显示任何内容。您可以使用标签对象、工具提示或其他GUI对象显示字符串。您需要找出要使用的正确GUI对象,并将文本传递给该对象对象visible
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="100" minHeight="100">
<fx:Script>
private function onMouseOver():void {
helpLabel.visible=true;
}
private function onMouseOut():void {
helpLabel.visible=false;
}
</fx:Script>
<s:Image id="helpIcon" x="270" y="187"
width="50" height="50"
mouseOver="onMouseOver()" mouseOut="onMouseOut()"
source="source_path"/>
<!-- note the mouse event handlers are so simple in this case, you can also do them in line -->
<s:Image id="alternateMethod" mouseOver="helpLabel.visible=true;"
mouseOut="helpLabel.visible=false;" />
<s:Label id="helpLabel" x="100" y="100" visible="false" text="Some Text."/>
</s:Application>
onMouseOver()的私有函数:void{
helpLabel.visible=true;
}
onMouseOut()的私有函数:void{
helpLabel.visible=false;
}
首先,您应该创建新的文本
元素,该元素具有id='helpText'
我已经创建了::::private var helpText:String=“Some text.”感谢您的及时响应。我也尝试过了,但没有区别:(顺便问一下,帮助文本应该显示在哪里?在代码中,您只有一个定义帮助文本的变量,但据我所知,您从未将其放在“场景”中。您尝试过使用trace()吗?);以确保您的活动正常进行?你好,Sunil.。非常感谢。非常感谢。我的代码正在运行。也非常感谢您及时回复我!!
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="100" minHeight="100">
<fx:Script>
private function onMouseOver():void {
helpLabel.visible=true;
}
private function onMouseOut():void {
helpLabel.visible=false;
}
</fx:Script>
<s:Image id="helpIcon" x="270" y="187"
width="50" height="50"
mouseOver="onMouseOver()" mouseOut="onMouseOut()"
source="source_path"/>
<!-- note the mouse event handlers are so simple in this case, you can also do them in line -->
<s:Image id="alternateMethod" mouseOver="helpLabel.visible=true;"
mouseOut="helpLabel.visible=false;" />
<s:Label id="helpLabel" x="100" y="100" visible="false" text="Some Text."/>
</s:Application>