开发者

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.

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. In other preloaders I have seen with code like this, it uses a movieclip with 100 frames. 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 = M开发者_开发技巧ath.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.

EDIT: progress_bar is a movieclip which was exported for actionscript.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜