troubleshooting Question

AS3: continially fire a function when mouse is held down?

Avatar of cubical38
cubical38 asked on
Adobe FlashWeb Graphics Software
4 Comments1 Solution611 ViewsLast Modified:
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...
stop();
 
import gs.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
try {
	photos.stop();
	pre_mc.y = -300;
	var startX:Number;
	var startFrame:int;
	var changeDistance:int;
	var travelDistance:int;
 
	TweenGroup.allTo([moveLeft_btn, moveRight_btn], .5, {alpha:.5, ease:Strong.easeIn});
 
	moveLeft_btn.addEventListener(MouseEvent.MOUSE_DOWN , moveLeftMouseDown);
	moveLeft_btn.addEventListener(MouseEvent.MOUSE_UP , moveLeftMouseUp);
	//stage.addEventListener(MouseEvent.MOUSE_UP , moveLeftMouseUp);
 
	function moveLeftMouseDown(MouseEvent) {
		photos.gotoAndPlay.nextFrame();
 
	}
	function moveLeftMouseUp(MouseEvent) {
 
	}
 
	moveRight_btn.addEventListener(MouseEvent.MOUSE_DOWN , moveRightMouseDown);
	moveRight_btn.addEventListener(MouseEvent.MOUSE_UP , moveRightMouseUp);
	//stage.addEventListener(MouseEvent.MOUSE_UP , moveRightMouseUp);
 
	function moveRightMouseDown(evt) {
		photos.gotoAndPlay.prevFrame();
 
	}
	function moveRightMouseUp(evt) {
 
	}
 
	moveLeft_btn.buttonMode = true;
 
	moveLeft_btn.addEventListener(MouseEvent.MOUSE_OVER,changeColor);
	moveLeft_btn.addEventListener(MouseEvent.MOUSE_OUT,changedColor);
 
	function changeColor(MouseEvent):void {
		moveLeft_btn.alpha = 1;
	}
	function changedColor(MouseEvent):void {
		moveLeft_btn.alpha = .5;
	}
	moveRight_btn.buttonMode = true;
 
	moveRight_btn.addEventListener(MouseEvent.MOUSE_OVER,changeColor1);
	moveRight_btn.addEventListener(MouseEvent.MOUSE_OUT,changedColor1);
 
	function changeColor1(MouseEvent):void {
		moveRight_btn.alpha = 1;
	}
	function changedColor1(MouseEvent):void {
		moveRight_btn.alpha = .5;
	}
 
	photos.buttonMode = true;
	photos.addEventListener(MouseEvent.MOUSE_DOWN,
	  pressHandler);
 
	function pressHandler(evt:MouseEvent):void {
		startX = photos.mouseX;
		startFrame = photos.currentFrame;
		photos.addEventListener(MouseEvent.MOUSE_MOVE,
		    moveHandler);
		stage.addEventListener(MouseEvent.MOUSE_UP,
		    releaseHandler);
	}
	function releaseHandler(evt:MouseEvent):void {
		photos.removeEventListener(MouseEvent.MOUSE_MOVE,
		    moveHandler);
		stage.removeEventListener(MouseEvent.MOUSE_UP,
		    releaseHandler);
	}
 
	function moveHandler(evt:MouseEvent):void {
		changeDistance = Math.round((photos.mouseX
		    - startX) / 18);
		travelDistance = startFrame + changeDistance;
		if (travelDistance > photos.totalFrames) {
			photos.gotoAndStop(travelDistance %
			      photos.totalFrames);
		} else if (travelDistance < 0) {
			photos.gotoAndStop(photos.totalFrames +
			      (travelDistance % photos.totalFrames));
		} else {
			photos.gotoAndStop(travelDistance);
		}
	}
} catch (error:TypeError) {
	trace("IOTypeError catch: " + error);
} finally {
	trace("Finally!");
}
ASKER CERTIFIED SOLUTION
scooby_56

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros