Dynamically skipping animations in Edge Animate

This post is more than 2 years old.

As much as I like animation, sometimes less is more. I know we've all seen cool animations that were, well, cool, but after you've seen it a few times you wish you could simply bypass it. Here's a simple example of how you can modify an Edge Animate project to remember that a user has seen the animation and skip to the end.

I began by creating an incredibly simple animation. I added a text box that flew in and increased in size. The entire animation stretched out over 3 seconds. Take a gander at the demo here: http://www.raymondcamden.com/demos/2012/dec/4/welcomeproject2/

Amazing, right? I know, I'm wasting my time as a developer when I should be in the interactive design business. Ok, that aside, the first thing I did was disable autoplay and created a "creationComplete" event handler. I discussed this earlier in another blog post: Data-driven Edge Animate Projects.

At this point I've got an animation that won't do anything, so I need to build that logic in. I decided to use window.sessionStorage as a simple way to note that you've already seen the animation. There's many other options I could have used, like cookies, but I figured this was the quickest, simplest way of doing it. Let's take a look at the code.

In a nutshell, the code first checks to see if your browser even supports sessionStorage, and if it does, it looks for the existence of a "seenanimation" variable. Again, we have options here. Instead of a "once a session" flag I could use a counter. Or a date variable that only shows the animation every 5 minutes. You get the idea.

The else portion is interesting. My animation is 3 seconds long. So at first I tried play(3000) but it didn't work. I then added a label called "End" and tried play("End"). Turns out, the play() API is 0-based. (Documented here.) So I simply used the getDuration() API and substracted one from it.

Obviously you wouldn't have to go to the end either. Maybe you just want to skip part of the animation or go to some other label. You can play with this demo below.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Adam Finch posted on 1/11/2013 at 7:52 AM

Hey Raymond, Great blog.

You mention that you don't have to skip to the end--how might you do that? I've tried play(label) in skipping part of my animation with no success. Could you elaborate on how to skip to a specific time or label?


Comment 2 by Raymond Camden posted on 1/11/2013 at 4:46 PM

Check out the code in background.js, specifically fireScrubTo. Notice how it works with the duration of the animation? You have access to it, so a method to go to the end would just use that. *But* please note you can't scrub to duration, but only duration-1.

Comment 3 by Adam Finch posted on 1/11/2013 at 9:17 PM

thanks for getting back to me. For some reason the creationComplete event handler never worked for me the way I wanted (it would play the first time, but wouldn't play or skip to the end after that), but I figured out another way.

Instead of turning off autoplay and using creationComplete I left autoplay on and set a trigger action at 0ms. The rest of it was the same.


Comment 4 by Raymond Camden posted on 1/11/2013 at 9:19 PM

Glad you got it, because my comment, while technically right, was in context of a completely different blog post I did. I blame the pain meds.

Comment 5 by Steve posted on 11/5/2013 at 8:47 PM

Is there any way you could make the edge project file available? I'm relatively new to javascript and edge animate, but if I could see how you setup your elements it would make my year. I tried adding the script above to my stage as a creationComplete and I turned off autoplay, but now I'm not getting any animation whatsoever when I preview it in my browser. Awesome post, I appreciate any help you can provide!

Comment 6 by Raymond Camden posted on 11/6/2013 at 3:47 AM

When I did my upload I uploaded everything, but obviously you can't see that. I just zipped up the entire folder. You can find it here:


Comment 7 by Michael M posted on 10/30/2014 at 4:44 AM

This seems to be broken in the latest version of Muse. At least from Muse it throws an error when creating an action.

"There are JavaScript syntax errors in this Edge Animate composition's actions.

Event Handlers cannot be created until these problems are fixed."


Comment 8 by Raymond Camden posted on 10/30/2014 at 4:56 AM

See my post here, http://www.raymondcamden.co.... EA changed some stuff recently and most of my demos no longer work (but are easily fixable).