简体   繁体   中英

Reverse/Playback AS3 Timeline

I'm trying to make a reversed play module in Action Script 3. I have a video, 200 frames long that I imported to Flash as a movie clip. I name the movie clip and inserted some key frames to make the video stop at specific frames, making it a 3 stage animation.

Whenever I swipe/pan to the right (detecting a positive x offset) it gives the command play(); , the movie clip will play til it finds a stop.

What I want to achieve is to play it backwards from the current frame til the previous stop when I swipe to the left (detecting a negative offset).

I sorted out the swipe/touch programming and what I'm missing is the backwards bit. I've managed to make it work, going backwards 1 single frame, not the whole bunch that exist prior to hit the previous stop frame. My code for the swipe and play forward is this, with the single prev frame included, which gives me just one frame back instead of the whole set before the previous stop.

Multitouch.inputMode = MultitouchInputMode.GESTURE;
mymovieclip.stop();

mymovieclip.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe); 

function onSwipe (e:TransformGestureEvent):void{
    if (e.offsetX == 1) { 
        //User swiped right
        mymovieclip.play();
    }
    if (e.offsetX == -1) { 
        //User swiped left
        mymovieclip.prevFrame();
    } 
}

You could try this:

import flash.events.Event;
import flash.display.MovieClip;

//note that this is not hoisted, it must appear before the call
MovieClip.prototype.playBackward = function():void {
    if(this.currentFrame > 1) {
        this.prevFrame();
        this.addEventListener(Event.ENTER_FRAME, playBackwardHandler);
    }
}

function playBackwardHandler(e:Event):void {
    var mc:MovieClip = e.currentTarget as MovieClip;
    if(mc.currentFrame > 1 && (!mc.currentFrameLabel || mc.currentFrameLabel.indexOf("stopFrame") == -1)) { //check whether the clip reached its beginning or the playhead is at a frame with a label that contains the string 'stopFrame'
        mc.prevFrame();
    }
    else {
        mc.removeEventListener(Event.ENTER_FRAME, playBackwardHandler);
    }
}

var clip:MovieClip = backMc; //some clip on the stage
clip.gotoAndStop(100); //send it to frame 100
clip.playBackward(); //play it backwards

Now you can put 'stopFrame' label to the clip's timeline (stopFrame1, stopFrame2... stopFrameWhatever) and the clip should stop there until playBackward is called again. Note that you should remove the enter frame event listener if the clip hasn't reached a stopFrame or its beginning and you want to call play/stop from the MovieClip API, otherwise it may cause problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM