AS3中的时间线Seekbar

时间:2016-01-20 12:41:34

标签: actionscript-3 flash seekbar

我正在尝试使用flash动作脚本项目来包含用于时间轴框架导航的自定义搜索栏。现在我可以让拖动器相对于总框架在搜索栏上移动。但拖动搜索栏会带来错误。此外,我想包括计时器,以显示分钟和秒数。

var ratio = 0; 
ratio = this.totalFrames/main.line.width;
var go = 0;
var isComplete = false;
var tFrame = this.totalFrames;
var isPress = false;

stage.addEventListener(Event.ENTER_FRAME, drag);
function drag(event:Event):void {   
if(main.dragger.x<=main.line.width){
    main.dragger.x = this.currentFrame/ratio;
}
}

main.dragger.addEventListener(MouseEvent.MOUSE_DOWN, drag1);
 function drag1(event:MouseEvent):void {    
  main.dragger.startDrag(false, new Rectangle(0, 9.2, main.line.width, 9.2));
  isPress = true;
  main.dragger.addEventListener(Event.ENTER_FRAME, frame);
}

function frame(event:Event):void
{
    trace (this.currentFrame);
    if(this.currentFrame < tFrame){
        gotoAndPlay(Math.round(main.x*ratio));
    }else{
        gotoAndPlay(tFrame-1);
    }

}
main.dragger.addEventListener(MouseEvent.MOUSE_UP,release);

function release(event:MouseEvent):void {
  main.dragger.stopDrag();
  main.dragger.removeEventListener(MouseEvent.MOUSE_DOWN, drag1);
}

当我点击拖动器移动时,它会自动跳到起始位置,并且gotoAndPlay也跳到那个位置并持续停留在那里..

附件: https://drive.google.com/open?id=0B4UOEUQTrhB0a21EaUpaUE52MGM

更新 这是在adobe论坛中发现的另一种方法,但这也给出了同样的拖拽问题。

var tl:MovieClip=this;
tl.addEventListener(Event.ENTER_FRAME,enterframeF);

paramF(tl,1,0,tl.totalFrames,slider.line.width);  // create a horizontal slider movieclip that contains a track movieclip and a thumbscroll movieclip that do the obvious and have left-sided reg point
paramF(slider,0,1,slider.line.width-slider.thumbscroll.width,tl.totalFrames);
var scrollRect1:Rectangle=new Rectangle(0,0,slider.line.width-slider.thumbscroll.width,0);

function enterframeF(e:Event):void{
slider.thumbscroll.x=tl.m*tl.currentFrame+tl.b;
}

slider.thumbscroll.addEventListener(MouseEvent.MOUSE_DOWN,scrolldownF);
slider.thumbscroll.addEventListener(MouseEvent.MOUSE_UP,scrollupF);

function scrolldownF(e:MouseEvent):void{
tl.removeEventListener(Event.ENTER_FRAME,enterframeF);
slider.thumbscroll.startDrag(false,scrollRect1);
slider.addEventListener(Event.ENTER_FRAME,scrollF);
}
function scrollupF(e:MouseEvent):void{
tl.addEventListener(Event.ENTER_FRAME,enterframeF);
slider.thumbscroll.stopDrag();
slider.removeEventListener(Event.ENTER_FRAME,scrollF);
}
function scrollF(e:MouseEvent):void{
tl.gotoAndStop(Math.round(slider.thumbscroll.x*slider.m+slider.b));
}


function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void{
mc.m=(y1-y2)/(x1-x2);
mc.b=y2-mc.m*x2;
}

0 个答案:

没有答案