AS3 外部预加载器可以在 Flash CS5 中工作,但不能在浏览器(chrome、Ff 或 IE)中工作 - 保持在 100%
我看到了几个已解决的问题,但没有一个问题特定于我正在使用的代码,所以我想知道是否有人可以提供帮助。
我正在使用外部预加载器 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须检查 ProgressEvent 处理程序中是否已加载 100%。
complete
事件有时不会触发。另外,请确保 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.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.