Get the Animation to Stop Looping using JS and HTML5
Overview
Daniel Scott
Founder of Bring Your Own Laptop & Chief Instructor
instructorI discovered the world of design as an art student when I stumbled upon a lab full of green & blue iMac G3’s. My initial curiosity around using the computer to create ‘art’ developed into a full-blown passion, eventually leading me to become a digital designer and founder of Bring Your Own Laptop.
Sharing and teaching are a huge part of who I am. As a certified Adobe instructor, I've had the honor of winning multiple Adobe teaching awards at their annual MAX conference. I see Bring Your Own Laptop as the supportive community I wished for when I was first starting out and intimidated by design. Through teaching, I hope to bring others along for the ride and empower my students to bring their stories, labors of love, and art into the world.
True to my Kiwi roots, I've lived in many places, and currently, I reside in Ireland with my wife and kids.
Hey there, in this video were going to look at how to stop an animation using some JavaScript. You'll notice if I preview, by default it really wants to loop for a bit. It goes back to the beginning and then loops back around. So what were going to do is we’re going to go through and add a bit of code just to make it stop.
So what you want to do is you want to have your play head along where you wan it to stop, I'm going to get mine to stop at the end, I'm going to click in any of these last frames, it doesn’t matter, its quite cool what used to happen is you used to have to create your own layer, call it actions create a key frame, all sorts of stuff so if you're old school flash, you don’t have to worry about that stuff anymore, all you need to do is have your timeline along here, I'm going to go to window, go to actions. He's hidden down here, and then I'm going to go code snippet, if its greyed out it means that you’ve clicked up here in the timeline but maybe not on any associated frame down here. So sometimes it’s greyed out.
Hit on code snippets, and in this code snippet you want the one that says html5 canvas, timeline navigation and this one here, stop at this frame. Double click, there's the code there and you can see down here its created a new layer for me called actions and its created a key frame for it and if I click off, you'll see the ‘a’, it means there's an action applied to it, its not action script, its JavaScript. And that’s what it is there. That’s the thing that will get it to stop, lets preview, plays once, and wobbly arm stops.
Alright, so that’s how to add an action and how to get your animation to stop using JavaScript.