Skip to main content
Known Participant
April 30, 2018
Answered

Click and drag image sequence back and fourth, stop at first frame and last frame

  • April 30, 2018
  • 1 reply
  • 349 views

I've imported an image sequence into flash, only 10 frames. I want to be able to scrub the sequence back and forth, but I want the mc to stop when I reach the first frame and stop when I reach the last frame. Below is code I used from a previous post, which works for 360s but again I want it to stop when the first and last frames are reached.

Any help is appreciated.

photos.stop();

//

var startX:Number;

var startFrame:Number;

var changeDistance:Number;

var travelDistance:Number;

photos.addEventListener(MouseEvent.MOUSE_DOWN,pressHandler);

function pressHandler(e:MouseEvent):void {

stage.addEventListener(MouseEvent.MOUSE_UP,releaseHandler);

startX = photos.mouseX;

startFrame = photos.currentFrame;

stage.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);

}

function releaseHandler(e:MouseEvent):void {

stage.removeEventListener(MouseEvent.MOUSE_UP,releaseHandler);

stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);

}

function moveHandler(e:MouseEvent):void {

changeDistance = photos.mouseX - startX;

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);

}

}

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

Remove the branching from the moveHandler function.

Like this:

function moveHandler(e:MouseEvent):void

{

    changeDistance = photos.mouseX - startX;

    travelDistance = startFrame + changeDistance;

  

    photos.gotoAndStop(travelDistance);

}

I hope it helps.

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
April 30, 2018

Hi.

Remove the branching from the moveHandler function.

Like this:

function moveHandler(e:MouseEvent):void

{

    changeDistance = photos.mouseX - startX;

    travelDistance = startFrame + changeDistance;

  

    photos.gotoAndStop(travelDistance);

}

I hope it helps.

Regards,

JC

Known Participant
April 30, 2018

Thanks for the quick response JC.