反向/播放 AS3 时间线



我正在尝试在动作脚本 3 中制作一个反向播放模块。我有一个视频,200帧长,我作为影片剪辑导入到Flash。我命名影片剪辑并插入一些关键帧,使视频在特定帧处停止,使其成为 3 阶段动画。

每当我向右滑动/平移(检测到正 x 偏移)时,它都会发出命令play();,影片剪辑将播放,直到找到停止点。

我想要实现的是当我向左滑动时,从当前帧向后播放它,直到上一站(检测负偏移)。

整理了滑动/触摸编程,我缺少的是向后位。我已经设法让它工作,倒退 1 个单帧,而不是在击中前一个停止帧之前存在的整堆。我的滑动和向前播放的代码是这样的,包括单个上一帧,它只给了我一帧,而不是上一站之前的整个集。

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

你可以试试这个:

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

现在,您可以将"stopFrame"标签添加到剪辑的时间轴上(stopFrame1,stopFrame2...stopFrameWhatever),剪辑应该停在那里,直到再次调用 playBack。请注意,如果剪辑尚未到达 stopFrame 或其开头,并且您希望从影片剪辑 API 调用播放/停止,则应删除输入帧事件侦听器,否则可能会导致问题。

最新更新