我有一部嵌入我的flash时间轴的电影,这样我就可以使用我创建的滚动条类逐帧滚动它。但是,由于电影大约是10mb,我需要在HTML5或flash中使用某种预加载器来显示海报图像或其他内容,直到电影加载完毕。我使用预加载器动态加载了影片剪辑,但是如果将影片剪辑嵌入时间轴中,该怎么办呢?我尝试了一个$(window).ready函数来隐藏窗口准备好的海报图像,因为我认为在你的所有资产都被加载之前它不会被触发,但我想这不适用于flash,所以我想我必须在闪光灯内完成它。
答案 0 :(得分:0)
在主动画片段(主时间轴上)上,您应该添加第一个空框架(它应该是轻量级并且加载速度快)。然后你应该停止(); MovieClip。停止后,您可以不断检查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);
}
答案 1 :(得分: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();
}
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();
}
跟踪语句甚至没有触发,时间线也没有前进。