AS3 Loader 不断地重新加载相同的 swf

发布于 2024-10-17 20:18:44 字数 1410 浏览 3 评论 0原文

我在 SWF 的主时间轴上制作了一个 Flash 动画,其中包含几个图层、一些功能和一些关键帧标签。例如,我有一个星星的电影剪辑,它出现在屏幕上,然后触发主时间轴的调度事件以转到帧标签“下一个”。

以下是主时间轴上使用的动作脚本示例:

Stars.addEventListener("fadeInTitle",_fadeInTitle);

function _fadeInTitle(e:Event):void {
    Title.gotoAndPlay("fadeIn");
    Stars.removeEventListener("fadeInTitle",_fadeInTitle);
}

stop();

SWF 单独运行效果很好。当我尝试将此 SWF 加载到另一个 SWF 时出现问题。 发生的情况是加载器不断地一遍又一遍地重新加载 SWF,使它们重叠,并且加载的 SWF 主时间轴上的动作脚本被忽略,时间轴连续播放。这是我用来加载 SWF 的代码:

import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;

function startLoad(){
    var mLoader:Loader = new Loader();
    var mRequest:URLRequest = new URLRequest("Fly.swf");
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    mLoader.load(mRequest);
}

function onCompleteHandler(loadEvent:Event){
    addChild(loadEvent.target.content);
}

function onProgressHandler(mProgress:ProgressEvent){
    var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}

startLoad();

没有什么特别的。只是一个简单的装载机。

我找到了一种解决方法,将整个动画放入一个主影片剪辑中,并将该影片剪辑放在主时间轴上(一个关键帧,一层,无动作脚本),然后加载它。这样它就可以正常工作,但感觉更像是一个补丁而不是解决方案。我真的很想知道为什么当您尝试加载使用具有多个图层、关键帧和动作脚本的主时间线的外部 SWF 时会出现问题。

任何帮助/提示将不胜感激。
非常感谢您的阅读。

I have a flash animation made on the main timeline of the SWF with a couple of layers, some functions and some keyframe labels. For example, i have a movieclip of a star that come across the screen and then triggers a dispatchEvent for the main timeline to go to frame label "next".

Here is a sample of the actionscript used on the main timeline :

Stars.addEventListener("fadeInTitle",_fadeInTitle);

function _fadeInTitle(e:Event):void {
    Title.gotoAndPlay("fadeIn");
    Stars.removeEventListener("fadeInTitle",_fadeInTitle);
}

stop();

That SWF alone works perfectly. Problem comes when I try to load this SWF into another one.
What happens is the loader keeps reloading the SWF over and over, overlapping them and the actionscript that's on the main timeline of the loaded SWF is ignored, the timeline plays continuously. Here is the code i use to load the SWF :

import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;

function startLoad(){
    var mLoader:Loader = new Loader();
    var mRequest:URLRequest = new URLRequest("Fly.swf");
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    mLoader.load(mRequest);
}

function onCompleteHandler(loadEvent:Event){
    addChild(loadEvent.target.content);
}

function onProgressHandler(mProgress:ProgressEvent){
    var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}

startLoad();

There's nothing special there. Just a simple loader.

I have found a workaround by putting the entire animation inside one main movieclip and put that movieclip on the main timeline (one keyframe, one layer, no actionscript) and then load it. That way it works fine but it feel more like a patch than a solution. I would really like to know why it's bugging when you try to load an external SWF that use the main timeline with multiple layers, keyframes and actionscript.

Any help/hint will be greatly appreciated.
Thanks a lot for reading.

m

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

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

发布评论

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

评论(1

一笑百媚生 2024-10-24 20:18:45

首先从函数中取出加载器实例化,这是没有必要的。其次,在 onComplete 函数中杀死你的听众。第三,如果此加载程序代码位于加载程序 shell 的时间轴上,请确保不超过一帧,或者如果有(但不确定为什么会出现),请在包含加载程序代码的帧上停止。或者更好的是,使用 Document 类来包含加载器代码,而不是将其放在时间线上。我最好的猜测是您以某种方式再次调用 startLoad() 。另外,请确保安装了 Flash 调试播放器,以便在浏览器中查看此内容时获得正确的错误报告。

var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("Fly.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);


function onCompleteHandler(loadEvent:Event)
{
    mLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    addChild(loadEvent.target.content);
}

function onProgressHandler(mProgress:ProgressEvent)
{
    var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}

First take the loader instantiation out of a function, it is not necessary. Second, kill your listeners in the onComplete function. Third, if this loader code is on the timeline of your loader shell, make sure that there is not more than one frame, or if there is (not sure why there would be though) place a stop on the frame containing the loader code. Or even better, use a Document class to contain your loader code rather than putting it on the timeline. My best guess is you were calling startLoad() over again somehow. Also, make sure you have the flash debug player installed so you are getting proper error reporting when viewing this in a browser.

var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("Fly.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);


function onCompleteHandler(loadEvent:Event)
{
    mLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    addChild(loadEvent.target.content);
}

function onProgressHandler(mProgress:ProgressEvent)
{
    var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文