AS3: continially fire a function when mouse is held down?
I need to be able to continue to scroll through a sequence of images when the mouse is held down. Right now when you click the button it only goes to the nextFrame or prevFram as you can see. Please review my code and let me know if there is a simpler way of doing this.
This is a sequence of 24 images that are run through causing the appearance of of a 360 rotation. Drag works perfectly but what I need to do is be able to click and hold the mouse down and cause the piece to run through the images and if they hit the last frame to continue to rotate through...
Under a tight deadline so any help is greatly appreciated...
on mouse down add an Enter Frame Event
each time the frame-event fires check which button is depressed and scroll appropriately
on mouse up, remove the Enter Frame Event
cubical38
ASKER
Okay cool that worked great, but one more thing. How do I determine the end of the sequence to return to the first or last frame depending on direction?
I tried and if else, but I dont think I am getting the syntax correct...
Here is my code:
moveLeft_btn.addEventListener(MouseEvent.MOUSE_DOWN , moveLeftMouseDown); moveLeft_btn.addEventListener(MouseEvent.MOUSE_UP , moveLeftMouseUp); //stage.addEventListener(MouseEvent.MOUSE_UP , moveLeftMouseUp); function moveLeftMouseDown(MouseEvent) { stage.addEventListener(Event.ENTER_FRAME, enterFrame); } function enterFrame(evnt:Event):void { photos.nextFrame(); } function moveLeftMouseUp(MouseEvent) { stage.removeEventListener(Event.ENTER_FRAME, enterFrame); } moveRight_btn.addEventListener(MouseEvent.MOUSE_DOWN , moveRightMouseDown); moveRight_btn.addEventListener(MouseEvent.MOUSE_UP , moveRightMouseUp); //stage.addEventListener(MouseEvent.MOUSE_UP , moveRightMouseUp); function moveRightMouseDown(MouseEvent) { stage.addEventListener(Event.ENTER_FRAME, enterFrames); } function enterFrames(evnt:Event):void { photos.prevFrame(); } function moveRightMouseUp(MouseEvent) { stage.removeEventListener(Event.ENTER_FRAME, enterFrames); }
each time the frame-event fires check which button is depressed and scroll appropriately
on mouse up, remove the Enter Frame Event