[英]Flash preloader: Not preloading properly?
The preloader does not show up after 3% like it should have, it shows up when the file has loaded entirely. 预加载器不会在应有的3%之后显示,而是在文件完全加载后显示。
Can someone help explain to me what I am doing wrong? 有人可以帮我解释我做错了什么吗? My code is in the first frame, and it makes use of a rectangle object, and a textfield object.
我的代码在第一帧中,它使用一个矩形对象和一个textfield对象。 In other preloaders I have seen with code like this, it uses a movieclip with 100 frames.
在其他预加载器中,我使用类似的代码看到过,它使用具有100帧的动画片段。 Does that make the difference?
会有所作为吗? I have code updating the width of the rectangle, and something to update the text in the dynamic textbox as well.
我有代码来更新矩形的宽度,还需要一些代码来更新动态文本框中的文本。
My entire code in the first frame: 我在第一帧中的全部代码:
import flash.display.MovieClip;
import flash.events.ProgressEvent;
function update(e:ProgressEvent):void {
//trace(e.bytesLoaded);
if (loader) {
loader.text = Math.round(e.bytesLoaded*100/e.bytesTotal).toString() + " %";
}
if (bar) {
bar.width = Math.round(e.bytesLoaded*100/e.bytesTotal)*2;
}
}
loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);
var loader:TextField = new TextField();
var bar:preloader_bar = new preloader_bar();
addEventListener(Event.ENTER_FRAME, checkFrame);
var loaderTextFormat:TextFormat = new TextFormat("_sans", 16, 0x000000, true);
loaderTextFormat.align = TextFormatAlign.CENTER;
loader.defaultTextFormat = loaderTextFormat;
bar.color = 0x000000;
addChild(bar);
addChild(loader);
// Extra test for IE
var percent:Number = Math.floor( (this.loaderInfo.bytesLoaded*100)/this.loaderInfo.bytesTotal );
if (percent == 100) {
nextFrame();
}
stop();
if (loader) {
loader.x = (stage.stageWidth - loader.width) / 2;
loader.y = stage.stageHeight / 2;
}
if (bar) {
bar.x = (stage.stageWidth - 200) / 2;
bar.y = (stage.stageHeight - bar.height) / 2;
}
function checkFrame(e:Event):void {
if (currentFrame == totalFrames) {
removeEventListener(Event.ENTER_FRAME, checkFrame);
startup();
}
}
function startup():void {
// hide loader
stop();
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, update);
var mainClass:Class = Main as Class;
addChild(new mainClass() as DisplayObject);
}
It really should be showing up, is there some fancy export option I need to change? 它确实应该显示出来,我是否需要更改一些精美的导出选项? I tried this with the bandwidth profiler, it only shows anything after the 100% mark.
我使用带宽分析器进行了尝试,它仅显示100%标记之后的任何内容。
EDIT: progress_bar is a movieclip which was exported for actionscript. 编辑:progress_bar是为动作脚本导出的动画片段。
You problem seem very similar to this . 您的问题似乎与此非常相似。
Short version: Do you have a single frame ? 简短版:您有一个框架吗? If so, move as much as you can on the 2nd frame and also set that as the Export Frame for actionscript.
如果是这样,请在第二帧上尽可能多地移动,并将其设置为动作脚本的“导出帧”。 Once your first frame has a small size, you will see the preloader easily.
一旦您的第一帧尺寸较小,您就可以轻松看到预加载器。
HTH, George 乔治·HTH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.