用于加载外部 SWF 的预加载器,无需 PROGRESS 和 COMPLETE 事件
我创建了以下预加载器,另存为“preloader.swf”,它加载外部 SWF 文件,如下所示:
var req:URLRequest = new URLRequest("main.swf");
var loader:Loader = new Loader();
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showContent);
var preloader:Preloader = new Preloader();
function showPreloader(event:Event):void
{
addChild(preloader);
preloader.x = (stage.stageWidth / 2) - (preloader.width / 2);
preloader.y = (stage.stageHeight / 2) - (preloader.height / 2);
}
function showProgress(event:ProgressEvent):void
{
var percent:Number = event.bytesLoaded / event.bytesTotal;
preloader.percentage.text = Math.round(percent * 100) + "%";
preloader.bar.width = 300 * percent;
}
function showContent(event:Event):void
{
removeChild(preloader);
addChild(loader);
}
我正在阅读以尝试避免 PROGRESS 和 COMPLETE 事件,因为这些事件并非 100% 的时间都有效。
现在我的问题是:有没有一种方法可以让我获得加载外部 SWF 文件(如上所述)的相同功能,但不使用 PROGRESS 和 COMPLETE 事件?
如果是这样,有人可以建议我添加/更改哪些编码吗?
谢谢。
I have created the following preloader saved as "preloader.swf" that loads an external SWF file as follows:
var req:URLRequest = new URLRequest("main.swf");
var loader:Loader = new Loader();
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showContent);
var preloader:Preloader = new Preloader();
function showPreloader(event:Event):void
{
addChild(preloader);
preloader.x = (stage.stageWidth / 2) - (preloader.width / 2);
preloader.y = (stage.stageHeight / 2) - (preloader.height / 2);
}
function showProgress(event:ProgressEvent):void
{
var percent:Number = event.bytesLoaded / event.bytesTotal;
preloader.percentage.text = Math.round(percent * 100) + "%";
preloader.bar.width = 300 * percent;
}
function showContent(event:Event):void
{
removeChild(preloader);
addChild(loader);
}
I was reading to try avoid the PROGRESS and COMPLETE events since these events don't work 100% of the time.
Now my question is this: is there a way of how I can go about to have the same functionality of loading an external SWF file (as above) but WITHOUT using the PROGRESS and COMPLETE events?
If so, can anyone suggest me what coding to add/change?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过用定时器吗?您每隔一段时间就会检查一下 SWF 是否已完全加载。
然而,PROGRESS 和 COMPLETE 事件应该始终有效。您的项目中有什么不起作用?
HAve you tried with a Timer? You check at every interval is the SWF is loaded entirely or not.
However , PROGRESS and COMPLETE events should always work. What's not working in your project?