最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any way to detect when a Swiffy animation has completed? - Stack Overflow

programmeradmin0浏览0评论

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

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

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

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

Share Improve this question edited Oct 31, 2020 at 21:05 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 6, 2012 at 17:05 bergie3000bergie3000 1,1311 gold badge14 silver badges21 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 6

For anyone who es 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.

Flash timeline frame script:

   import flash.navigateToURL;
   import flash.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);
 }

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.

发布评论

评论列表(0)

  1. 暂无评论