AS3:如何在加载的 swf 动画上使用帧脚本?
我尝试在已加载的 SWF 动画上使用 addFrameScript()
,但遇到了一些问题。现在的工作原理如下:
public function project() {
var loader:Loader = new Loader();
loader.load(new URLRequest("animation.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, animLoadComplete, false, 0, true);
}
private function animLoadComplete(e:Event):void {
anim = e.target.content as MovieClip;
addChild(anim);
//anim.addFrameScript(anim.totalFrames - 1, animEnd);
}
private function animEnd():void {
trace("animEnd");
}
像这样,动画播放 fin 并且一遍又一遍地循环。
问题似乎在于,无论使用 stop()
、play()
或任何动画函数,动画都会运行。 trace(anim.totalFrames)
还显示我的动画是 2 帧而不是 23 帧(实际上是 23 帧)。
当我取消注释 anim.addFrameScript(anim.totalFrames - 1, animEnd);
时,帧脚本似乎每帧都会被调用,并且动画停止播放,而是由 flash“加载点”代替” 它应该出现的地方。
我想我的问题是双重的。我是否正确加载动画?为什么框架脚本会导致我的动画消失?
I'm trying to use addFrameScript()
on a SWF animation I have loaded but am running into a few problems. Here's what works right now:
public function project() {
var loader:Loader = new Loader();
loader.load(new URLRequest("animation.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, animLoadComplete, false, 0, true);
}
private function animLoadComplete(e:Event):void {
anim = e.target.content as MovieClip;
addChild(anim);
//anim.addFrameScript(anim.totalFrames - 1, animEnd);
}
private function animEnd():void {
trace("animEnd");
}
Like this, the animation plays fin and just loops over and over again.
The trouble seems to be that the animation runs regardless of using stop()
, play()
or any animation function. A trace(anim.totalFrames)
also shows that my animation is 2 frames rather than 23 (which it is).
When I un-comment anim.addFrameScript(anim.totalFrames - 1, animEnd);
the frame script appears to be called every frame and the animation ceases to play and is instead replaced by the flash "loading dots" where it should appear.
I suppose my question is twofold. Am I loading in my animation properly and why does a framescript cause my animation to disappear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这个东西时,stop() 的路径/引用可能会很棘手。
我构建了一些实用程序以使其更容易,因为我经常这样做 - 实用程序也处理保留现有代码: http://flair-flash-flex-air.blogspot.com/2010/07/using-actionscript-3-to-inject- code.html
有一个链接,指向我在文章中创建的 util 类的要点。
但事实上,您加载的 swf 跟踪为具有 2 帧而不是您期望的 23 帧 - 正如您所注意到的 - 令人担忧!我预计这会导致您出现明显的问题(代码跟踪“每一帧”),就好像您只有 2 帧一样,那么您的脚本将在备用帧上运行。
您是否尝试过监听 INIT 而不是 COMPLETE?如果我想使用 swf 的内容,我通常会发现这更可靠。此外,您可能(取决于您的父 swf)需要设置 LoaderContext 属性的 SecurityDomain(您在执行 load() 时将其传递 - 请查看 Loader 的 AS3 文档以获取更多详细信息)。
pathing / referencing for that stop() can be tricky when using this stuff.
I built some utilities to make it easier because I was doing this a lot - the utils deal with preserving existing code too: http://flair-flash-flex-air.blogspot.com/2010/07/using-actionscript-3-to-inject-code.html
There's a link to a gist of the util classes I created within the article.
But the fact that your loaded swf is tracing as having 2 frames rather than the 23 you expect is - as you noticed - worrying! I expect this is causing your visible problem (the code tracing 'every frame') as if you've only got 2 frames then your script would be running on alternate frames.
Have you tried listening for INIT instead of COMPLETE? I usually find this more reliable if I want to use the swf's contents. Also you might (depending on your parent swf) need to set the SecurityDomain of the LoaderContext property (you'd pass this in when you do your load() - check out the AS3 docs for Loader for more details).