Is there any way to detect when a Swiffy animation has completed?

ⅰ亾dé卋堺 提交于 2019-12-04 14:19:22

问题


Do Swiffy animations trigger an event when they're complete? Or is there perhaps a way to grab the current frame vs. total frames?

I tried de-minifying runtime.js as mentioned in another SO post, but I can't decipher it.


回答1:


For anyone who comes across this post, I found a solution. I ended up using a getURL() call at the end of my FLA. It looks like this:

getURL("javascript:animationIsComplete();");

Put whatever you want in the animationIsComplete() function and it will now be triggered at the end of the Swiffy animation.




回答2:


Flash timeline frame script:

   import flash.net.navigateToURL;
   import flash.net.URLRequest;

   navigateToURL(new URLRequest("javascript:document.dispatchEvent(new CustomEvent('animation_done', {detail:{name:'sparkle'}}))"), "_self");
   stop();

Javascript:

 document.addEventListener("animation_done", animationDone, false);

 function animationDone(e /* Event */){
     console.log('animation done ' + e.detail.name);
 }



回答3:


In case anyone else stumbles across this question and is working with ActionScript 3 - the top answer will not work for them, as the getURL() function is only available in ActionScript 2 and earlier versions.

Use the following for ActionScript 3:

navigateToURL(new URLRequest("javascript:your_function()"), "_self");

Add that as an action to the final frame of your animation in Flash and then convert it using Swiffy. You can then take the output from Swiffy and work it into a webpage. Just make sure you define your JavaScript function somewhere in the source of the page that displays the Swiffy animation.



来源:https://stackoverflow.com/questions/11366652/is-there-any-way-to-detect-when-a-swiffy-animation-has-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!