1

在这段代码中,我需要一个进度条来播放导入的 .swf 文件,同时我应该能够在进度条中拖动拖动器(即拖动器的移动速度应该与 .swf 文件播放的速度同步)。我得到参数错误:#2109 在场景 1 中找不到帧标签 459.99。

var loader:Loader = new Loader();
playBtn.visible = true;

pauseBtn.visible = false;
btn_00.addEventListener(MouseEvent.CLICK, fileLoaded);
btn_01.addEventListener(MouseEvent.CLICK, fileLoaded);
btn_02.addEventListener(MouseEvent.CLICK, fileLoaded);
function fileLoaded(evt:MouseEvent):void
{
    var fileName:String = evt.currentTarget.name;
    var fileNumber:String = fileName.split("_")[1];
    var urlPath:String = "assets/file_" + fileNumber + ".swf";
    loader.load(new URLRequest(urlPath));
    addChild(loader);
}
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
function swfLoaded(event:Event):void
{
    addEventListener(Event.ENTER_FRAME, trackPlayback);
}
function trackPlayback(event:Event):void
{
    var perPlayed:Number = MovieClip(loader.content).currentFrame / MovieClip(loader.content).totalFrames;
    progressbar.drag.x = (progressbar.bar.width - progressbar.drag.width) * perPlayed;
}
progressbar.drag.buttonMode = true;
var dragClicked:Boolean = false;
var xpos:Number = progressbar.bar.x * progressbar.drag.width;
progressbar.drag.addEventListener(MouseEvent.MOUSE_DOWN,dragMouseDown);
function dragMouseDown(evt:MouseEvent):void
{
    trace(" inside mouse down ");
    dragClicked = true;
    progressbar.drag.startDrag(false,new Rectangle(xpos,0,progressbar.width-progressbar.drag.width,0));
}

progressbar.drag.addEventListener(MouseEvent.MOUSE_UP,dragMouseUp);
function dragMouseUp(evt:MouseEvent):void
{
    dragClicked = false;
    progressbar.drag.stopDrag();
    var cnt:Number = (progressbar.drag.x/(progressbar.width-progressbar.drag.width))*MovieClip(loader.content).totalFrames;
    MovieClip(loader.content).gotoAndPlay(cnt);
  }

请解决我的问题。

提前致谢。

4

1 回答 1

0

要访问特定帧,您需要提供一个整数值,此时您正在使用浮点值。

一个简单的解决方法是将其Number转换为int

MovieClip(loader.content).gotoAndPlay(int(cnt));
于 2012-11-26T11:35:39.690 回答