Here is a simple code snippet to use with any timeline-based Flash project that will save you from pulling your hair out. If you are like me you still occasionally find yourself doing Flash projects that are strictly timeline-based. No matter how much you love doing class-based AS projects, there are certain projects that just make sense to do with the timeline. Think banner ad animations and linear “Flash commercial” type projects, where it’s just two minutes straight of animation.
Testing these projects inside of Flash is a pain. If you are testing the movie and there is a certain section of the movie you want to review, you always end up having to sit through parts of the movie waiting for the part you want to come up. Anyone who has had to work with a 3,000 frame timeline knows what I am talking about.
The solution is simple but I can almost guarantee that once you use this trick you will start using it every single time you are working with a timeline.
The trick is to add keyboard arrow controls to the movie.
Up restarts the movie.
Down pauses/unpauses the movie.
Left jumps back 30 frames.
Right jumps forward 30 frames.
Now when you are testing you can just press the arrows to jump through the movie to get to the different parts.
So if you want to review how a certain text transition looks, or pause the screen to double check you have the correct copy, or skip ahead to a certain part of the movie to review, just use the arrows.
Add this script to the first frame of your animation and you are all set:
-
var framesToSkip:int = 30;
-
var isPaused:Boolean = false;
-
-
function arrowControl(event:KeyboardEvent):void {
-
if (event.keyCode == 38) {
-
gotoAndPlay(1);
-
}
-
if (event.keyCode == 40) {
-
if (isPaused == true) {
-
play();
-
isPaused = false;
-
}
-
else {
-
stop();
-
isPaused = true;
-
}
-
}
-
if (event.keyCode == 37) {
-
gotoAndPlay((currentFrame – framesToSkip));
-
}
-
if (event.keyCode == 39) {
-
gotoAndPlay((currentFrame + framesToSkip));
-
}
-
}
-
-
stage.addEventListener(KeyboardEvent.KEY_DOWN, arrowControl);
Feel free to download the example and use it however you like.
ยป Download the sample zip file
__
Related posts:



I know exactly what you mean…previewing long animations over and over gets old. Never though to add this type of functionality – thanks for the insight!
Thank you for the tip!
I added something like this to a couple of the longer animations I’d done – but for some reason it didn’t occur to me to code the arrow keys. Instead, I made a little navigation bar that I inserted into movies I was working on/testing – of course then I had to press buttons instead of using the handy keystrokes. this is a much better solution!
If I won the Aspen Flash template, I’d use it for our non-profit film and art school we pioneered that offers free CG modeling, video camera, lighting, & editing skills for at-risk youth
If I could reach your feet, I would fall down and slather them with grateful kisses. I’m working on a 4+ minute slideshow, and trying to preview beyond the first 30 seconds has been driving me nuts. This is an AWESOME solution!!!!!!!!!!!!!
Nice suggestion, I could have used this for an animation I did recently. I was using a simple gotoAndPlay(); action but this is a more elegant solution