0

我有一个嵌入在我的 Flash 时间轴中的电影,这样我就可以使用我创建的滚动条类逐帧滚动它。然而,因为电影大约 10mb,我需要有某种预加载器,无论是 HTML5 还是 Flash 中,以显示海报图像或其他东西,直到电影被加载。我已经使用预加载器动态加载了影片剪辑,但是当影片剪辑嵌入到时间线中时,我该怎么做呢?我尝试了一个 $(window).ready 函数来隐藏窗口准备好的海报图像,因为我认为这在加载所有资产之前不会触发,但我想这不适用于 flash,所以我想我'将不得不在 Flash 内完成。

4

2 回答 2

0

在主动画剪辑上(在主时间轴上),您应该添加第一个空帧(它应该是轻量级的并且加载速度快)。那么你应该 stop(); 影片剪辑。停止后,您可以继续检查 loaderInfo.bytesLoaded/loaderInfo.bytesLoaded 属性并显示加载过程的百分比。

此代码段可能会有所帮助(您可以将此代码放入时间线的第一帧,或放入 Main 类构造方法):

//create a text field to show the progress
var progress_txt:TextField = new TextField();
//stop the timeline, will play when fully loaded
stop();
//position text field on the centre of the stage
progress_txt.x = stage.stageWidth / 2;
progress_txt.y = stage.stageHeight / 2;
addChild(progress_txt);

//add all the necessary listeners
loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
loaderInfo.addEventListener(Event.COMPLETE, onComplete);


function onProgress(e:ProgressEvent):void
{
  //update text field with the current progress
  progress_txt.text = String(Math.floor((e.bytesLoaded/e.bytesTotal)*100));
}

 function onComplete(e:Event):void
{
  trace("Fully loaded, starting the movie.");
  //removing unnecessary listeners
  loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
  loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
  //go to the second frame. 
  //You can also add nextFrame or just play() 
  //if you have more than one frame to show (full animation)
  gotoAndStop(2);
}
于 2012-12-02T14:17:20.373 回答
0

我不确定为什么这对我不起作用..

这是我的代码,在主时间线上:

stop();

var percent:Number; //used to show loader progress

loaderInfo.addEventListener(Event.COMPLETE, onGameLoaded);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
trace(loaderInfo.bytesLoaded, loaderInfo.bytesTotal);

function onLoaderProgress(event: ProgressEvent): void {
    trace("Progress called");
    percent = (event.bytesLoaded / event.bytesTotal);
    preloader.bar.scaleX = percent;
    preloader.percentageTxt.text = String(Math.round(percent * 100)) + "%";
}

//Event-handler for when this main controller is completely loaded
function onGameLoaded(event: Event): void {
    loaderInfo.removeEventListener(Event.COMPLETE, onGameLoaded);
    loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
    trace("Game completely loaded");
    play();
}

跟踪语句甚至没有触发,时间线也没有向前移动。

于 2014-03-04T05:38:44.710 回答