AS3 外部预加载器可以在 Flash CS5 中工作,但不能在浏览器(chrome、Ff 或 IE)中工作 - 保持在 100%

发布于 2024-10-16 06:02:09 字数 2316 浏览 2 评论 0原文

我看到了几个已解决的问题,但没有一个问题特定于我正在使用的代码,所以我想知道是否有人可以提供帮助。

我正在使用外部预加载器 (loader.swf) 来加载电影 (ayproj.swf)。在 flash 播放器中运行 .swf 文件以及在 flash cs5 中模拟下载时,预加载器工作正常,但是当我将其上传到互联网并打开 flash 处于 100% 帧的 index.html 时,它要么停留在 100 %(Ff 和 IE)或只是说“pl”(chrome)-动态百分比文本框中的初始文本。

预加载器的代码是:

stop();

import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.Loader;
import com.greensock.TweenNano;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, onStageResize);
addEventListener(Event.ENTER_FRAME, onFrame);

var barcomp:Number = stage.stageWidth;
percentContainer.x = stage.stageWidth/2 - percentContainer.width/2;
percentContainer.y = stage.stageHeight/2 - percentContainer.height/2;

function onStageResize(evt:Event):void {

    bar_mc.x = 0;
    bar_mc.y = (stage.stageHeight) - 3;
    bar_mc.height = 20;
    barcomp = stage.stageWidth;

    percentContainer.x = stage.stageWidth/2 - percentContainer.width/2;
    percentContainer.y = stage.stageHeight/2 - percentContainer.height/2;

}



function onFrame(evt:Event):void {

    bar_mc.x = 0;
    bar_mc.y = (stage.stageHeight) - 3;
    bar_mc.height = 20;
    barcomp = stage.stageWidth;

    percentContainer.x = stage.stageWidth/2 - percentContainer.width/2;
    percentContainer.y = stage.stageHeight/2 - percentContainer.height/2;   
}

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
loader.load(new URLRequest("ayproj.swf"));
loader.visible = false;

function loop(e:ProgressEvent):void {

    var perc:Number = e.bytesLoaded / e.bytesTotal;
    var s:String = Math.ceil(perc*100).toString()+"%";
    percentContainer.percent.text = s
    bar_mc.width = perc * barcomp;
}

function done(e:Event):void { 

    removeChildAt(getChildIndex(percentContainer)); 
    removeChildAt(getChildIndex(bar_mc));

    percentContainer.percent = null; 

    stage.addChild(loader);

    TweenNano.delayedCall(0.5, fadeInAyproj);
}

function fadeInAyproj():void {

    loader.visible = true;
    TweenNano.to(loader, 0.8, {alpha:0});
    TweenNano.from(loader, 0.8, {alpha:0});
}

如果有人能提供帮助,我将非常感激。

I have seen a couple of questions that have been resolved but none are specific to the code i'm using so i was wondering if anybody could help.

I am using an external preloader (loader.swf) to load the movie (ayproj.swf). The preloader works fine when running the .swf file in flash player and when simulating a download in flash cs5 but when i upload it to the internet and open the index.html in which the flash is in a 100% frame it either sticks on 100% (Ff and IE) or just says "pl" (chrome) - the initial text in the dynamic percentage text box.

The code for the preloader is:

stop();

import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.Loader;
import com.greensock.TweenNano;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, onStageResize);
addEventListener(Event.ENTER_FRAME, onFrame);

var barcomp:Number = stage.stageWidth;
percentContainer.x = stage.stageWidth/2 - percentContainer.width/2;
percentContainer.y = stage.stageHeight/2 - percentContainer.height/2;

function onStageResize(evt:Event):void {

    bar_mc.x = 0;
    bar_mc.y = (stage.stageHeight) - 3;
    bar_mc.height = 20;
    barcomp = stage.stageWidth;

    percentContainer.x = stage.stageWidth/2 - percentContainer.width/2;
    percentContainer.y = stage.stageHeight/2 - percentContainer.height/2;

}



function onFrame(evt:Event):void {

    bar_mc.x = 0;
    bar_mc.y = (stage.stageHeight) - 3;
    bar_mc.height = 20;
    barcomp = stage.stageWidth;

    percentContainer.x = stage.stageWidth/2 - percentContainer.width/2;
    percentContainer.y = stage.stageHeight/2 - percentContainer.height/2;   
}

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
loader.load(new URLRequest("ayproj.swf"));
loader.visible = false;

function loop(e:ProgressEvent):void {

    var perc:Number = e.bytesLoaded / e.bytesTotal;
    var s:String = Math.ceil(perc*100).toString()+"%";
    percentContainer.percent.text = s
    bar_mc.width = perc * barcomp;
}

function done(e:Event):void { 

    removeChildAt(getChildIndex(percentContainer)); 
    removeChildAt(getChildIndex(bar_mc));

    percentContainer.percent = null; 

    stage.addChild(loader);

    TweenNano.delayedCall(0.5, fadeInAyproj);
}

function fadeInAyproj():void {

    loader.visible = true;
    TweenNano.to(loader, 0.8, {alpha:0});
    TweenNano.from(loader, 0.8, {alpha:0});
}

I would be extremely grateful if anybody could help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-10-23 06:02:09

您还必须检查 ProgressEvent 处理程序中是否已加载 100%。 complete 事件有时不会触发。

function loop(e:ProgressEvent):void {

    var perc:Number = e.bytesLoaded / e.bytesTotal;
    if (perc >= 100) done (e);

//...more code
}

另外,请确保 ayproj.swf 与 index.html 位于同一文件夹中,或者使请求 url 相对于 index.html 的路径。

You have to check for 100% loaded in the ProgressEvent handler, as well. The complete event sometimes does not fire.

function loop(e:ProgressEvent):void {

    var perc:Number = e.bytesLoaded / e.bytesTotal;
    if (perc >= 100) done (e);

//...more code
}

Also, make sure ayproj.swf is located in the same folder as index.html, or make the request url relative to index.html's path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文