重复鼠标悬停事件(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 ; }更多推荐
发布评论