重复鼠标悬停事件(repeat a Mouse Over event)

编程入门 行业动态 更新时间:2024-10-27 15:20:22
重复鼠标悬停事件(repeat a Mouse Over event)

嗨,我有一个动作,当鼠标移动到左或右箭头形状的按钮上时,会在舞台上移动一个框。 下面的脚本就是这么做的。 但是我想要做的是让盒子重复移动,直到鼠标移出箭头按钮。 我已经尝试了所有方法,任何人都可以请我指出正确的方向。我已经删除了很多代码,但希望这足以说明我的观点。 谢谢米克

right_arrow.addEventListener(MouseEvent.mouseOver, moveR) ; left_arrow.addEventListener(MouseEvent.mouseOver, moveL) ; function moveL(e:MouseEvent) { box_image.x = box_image.x - 5 ; }

Hi I have an actionscript that moves a box across the stage when the mouse is over a left or right arrow shaped button . The script below does just that. BUT what I want to do is have the box repeatedly move until the mouse is moved off the arrow button . I have tried all ways can anybody please point me in the right direction .I have removed a lot of the code but hope this is enough to get my point across. Thanks Mick

right_arrow.addEventListener(MouseEvent.mouseOver, moveR) ; left_arrow.addEventListener(MouseEvent.mouseOver, moveL) ; function moveL(e:MouseEvent) { box_image.x = box_image.x - 5 ; }

最满意答案

你可以使用setInterval方法:

right_arrow.addEventListener(MouseEvent.mouseOver, handleMouseOver) ; right_arrow.addEventListener(MouseEvent.mouseOut, handleMouseOut) ; function handleMouseOver( event:MouseEvent):void { setTimeout( moveBoxR, 500 ); //every 500ms } function handleMouseOut( event:MouseEvent):void { clearTimeout( moveBoxR ); } function moveBoxR() { box_image.x -= 5 ; }

或ENTER_FRAME事件

right_arrow.addEventListener(MouseEvent.mouseOver, handleMouseOver) ; right_arrow.addEventListener(MouseEvent.mouseOut, handleMouseOut) ; function handleMouseOver( event:MouseEvent):void { addEventListener( Event.ENTER_FRAME, moveBoxR ) } function handleMouseOut( event:MouseEvent):void { removeEventListener( Event.ENTER_FRAME, moveBoxR ) } function moveBoxR(event:Event) { box_image.x -= 5 ; }

you could use the setInterval Method:

right_arrow.addEventListener(MouseEvent.mouseOver, handleMouseOver) ; right_arrow.addEventListener(MouseEvent.mouseOut, handleMouseOut) ; function handleMouseOver( event:MouseEvent):void { setTimeout( moveBoxR, 500 ); //every 500ms } function handleMouseOut( event:MouseEvent):void { clearTimeout( moveBoxR ); } function moveBoxR() { box_image.x -= 5 ; }

or the ENTER_FRAME Event

right_arrow.addEventListener(MouseEvent.mouseOver, handleMouseOver) ; right_arrow.addEventListener(MouseEvent.mouseOut, handleMouseOut) ; function handleMouseOver( event:MouseEvent):void { addEventListener( Event.ENTER_FRAME, moveBoxR ) } function handleMouseOut( event:MouseEvent):void { removeEventListener( Event.ENTER_FRAME, moveBoxR ) } function moveBoxR(event:Event) { box_image.x -= 5 ; }

更多推荐

本文发布于:2023-07-30 13:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   事件   repeat   Mouse   event

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!