AS3 Preloader在本地不起作用,loaderInfo ProgressEvent.PROGRESS事件不会触发

时间:2014-04-11 02:16:19

标签: actionscript-3 flash actionscript flash-cs5 preloader

制作自定义AS3预加载器时,我注意到当我的SWF在本地执行时(文件:///),当在Chrome等网络浏览器中预览时,预加载器会卡在加载屏幕中。

从远程服务器或通过独立的Flash Player执行时,它可以正常工作。我注意到其他有预加载器的SWF没有这个问题。我需要改变什么?

this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, preloaderProgress);

function preloaderProgress(event:ProgressEvent):void {

    var loadedPercent:Number = event.bytesLoaded/event.bytesTotal*100;

    if (loadedPercent == 100){
        this.gotoAndStop(2);
    }
}

2 个答案:

答案 0 :(得分:1)

本地加载速度非常快。您不仅应使用Event.COMPLETE而不是ProgessEvent检查文件是否已完全加载,而且还应确保在实际调用load之前注册侦听器,否则在注册侦听器之前文件可能最终完全加载。

答案 1 :(得分:0)

按照http://stephenscholtz.com/201110/single-movie-flash-preloading-as3

的示例

似乎没有ProgressEvent.COMPLETE,但是有一个Event.COMPLETE,有点令人困惑。

我将我的代码更改为以下内容,(还包括对右键菜单的一些调整,以禁止用户右键单击并在电影加载之前按下播放等)

//Initialize any variables
var loadedPercent:Number = 0;

//Remove all items from right click Flash Player menu (except Quality, and the mandatory About... & Settings...)
var cxMenu:ContextMenu = new ContextMenu();
cxMenu.hideBuiltInItems();
cxMenu.builtInItems.quality = true;
this.contextMenu = cxMenu;

/* or disable right click menu completely (Flash Player 11.2.202.228 and over) */
/* this.addEventListener(MouseEvent.RIGHT_CLICK, onMouseRightClick);
function onMouseRightClick(event:MouseEvent) 
{
    return false;
} */

//Disable shortcut keys and window menubar when played from desktop Standalone Flash Player app
if (Capabilities.playerType == "StandAlone" || Capabilities.playerType == "External") {
    fscommand("showmenu", "false");
    fscommand("trapallkeys", "true");
}

/* Preloader: begin */

//Update loading bar and percent text as SWF loads
function onProgress(e:Event) {

    //Get the amount of bytes that have been loaded / bytes total to load
    loadedPercent = this.loaderInfo.bytesLoaded/this.loaderInfo.bytesTotal*100;

    //Update the text of _preloaderProgress movieclip
    _preloaderProgress.text = int(loadedPercent)+"%";

    //Update the _preloaderBar amount by scaling horizontally as it loads
    _preloaderBar.scaleX = loadedPercent/100;

}

//Go to next frame after everything loads
function init(e:Event) {
    gotoAndStop(2);
}

//Attach the events to the stage
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, init);

/* Preloader: end */

//Stop to 1st frame and wait until it is loaded
stop();

这样可以让电影在远程和本地播放都没有问题。