Understanding timelines

show more Understanding timelines provides you with in-depth training on Developer. Taught by Todd Perkins as part of the ActionScript 3.0 in Flash Professional CS5 Essential Training show less
please wait ...

Understanding timelines

Timelines are somewhat infamous in Flash, and many programmers refuse to write code unless all assets can be contained within a single frame. While simultaneously working with ActionScript in Timelines can be tricky, with proper planning, you will be able to set up your Timelines and code to best work together. Let's take a look at some examples of why Timelines can be frustrating. I'll play the animation here. So we have some text on the screen, then it fades out, and a bear walks onto the Stage.

This is all controlled through motion tweens. Let's say we wanted to communicate with the bear through ActionScript. So we'll close the window and go to the first keyframe of the actions layer on the main Timeline and open up the Actions panel. Rather than navigating through my whole file, I can find the bear instance name, or give the bear an instance name, through the Insert Target Path button in the Actions panel. I'll click that button, click on main_mc, select BearWalking, and then it says, "Instance name required to use this object as a target." So I'll click Rename.

Now I will give it an instance name of 'bear.' I'll click OK, and now it has an instance name. If I click OK, then Flash will actually write the code to communicate with that object for me. I don't need object this there, so I'll just delete that, and I will have main_mc.bear. So let's say I want to put its x position at zero, so you can type .x = 0. Now I test the movie, and I get an error.

The reason why I get an error, it's because if you look at the Timeline, you'll see there is nothing on the main layer. And if I scroll to frame 100, you will see that the main layer is what contains main_mc. So I am trying to communicate with an object that doesn't exist. In order to communicate with that object, I need to put the Timeline code on a frame where the object exists. So I'll go to frame 1, open up the Actions panel, cut the code using Command+X or Ctrl+X, move to frame 100, select that keyframe of the actions layer, open up the Actions panel and paste the code with Command+V or Ctrl+V. Now when I test the movie, after the text fades out, you'll see the bear can be affected by ActionScript, and there he is, on the left side of the screen.

If you keep watching, you'll notice the bear moves over to the left and walks in again. Here is why that happens. Look at my keyframes in the Timeline. I have one keyframe on the main layer here, and then on frame 145, there is another keyframe on that same layer. So when that keyframe hits, that change that I made to the bear gets reset, and the bear then walks in.

Also notice that modifying the bear with ActionScript completely destroyed the animation that I created. So playing with Timelines, again, can be very tricky. You need to be very precise with how you set up your FLA files so that you can communicate effectively. One way you can do that is to keep objects that you are going to need to communicate with in one frame. So you have one keyframe, and you manipulate the object only with ActionScript.

If you have to have multiple keyframes, then maybe you can put different ActionScript for each keyframe and have the code reapply. In some instances, you are going to have to get really creative to pull it off. I don't say this to scare you away from working with Timelines, but you should know what you're dealing with. Now that you know potential problems of working with Timelines, make sure to set up all of your Timelines appropriately so you can best integrate interactivity.

Understanding timelines
Video duration: 4m 15s 7h 8m Beginner Updated May 23, 2012


Understanding timelines provides you with in-depth training on Developer. Taught by Todd Perkins as part of the ActionScript 3.0 in Flash Professional CS5 Essential Training

please wait ...