嗨我有一个动作脚本,当鼠标悬停在左箭头或右箭头形状的按钮上时,它会在舞台上移动一个框。下面的脚本就是这样做的。但我想要做的是重复移动框,直到鼠标从箭头按钮移开。我已经尝试了所有方法,任何人都可以指出我正确的方向。我删除了很多代码,但希望这足以让我的观点得到解决。谢谢米克
right_arrow.addEventListener(MouseEvent.mouseOver, moveR) ;
left_arrow.addEventListener(MouseEvent.mouseOver, moveL) ;
function moveL(e:MouseEvent) {
box_image.x = box_image.x - 5 ;
}
答案 0 :(得分:2)
您可以使用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 ;
}
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 ;
}
答案 1 :(得分:0)
只是一个建议,不知道它会有多顺利: