开发者

repeat a Mouse Over event

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,开发者_如何学JAVA moveL) ;

function moveL(e:MouseEvent)    {
box_image.x = 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 ;
}


Just a suggestion, don't know how smooth it will be though:

  • set a flag to indicate the mouse over
  • implement an on frame handler which checks the flag and if set moves the box
  • on mouse out, reset the flag
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜