Watching:

Understanding how ActionScript 3.0 code is processed in the Flash Player


show more Understanding how ActionScript 3.0 code is processed in the Flash Player 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 how ActionScript 3.0 code is processed in the Flash Player

Before you start writing your own code, you should be familiar with how that code is processed, so that you have an idea of how your applications will react when you start writing ActionScript. Remember that ActionScript runs in the Flash player, so your movie actually has to be playing in order for code to be processed. In Flash Pro, ActionScript can be placed in external files, which we'll talk about later, or in the Timeline in keyframes. You can tell where ActionScript is in the Timeline by looking for the lowercase a instead of a keyframe.

So I'll click the first keyframe of layer 1, and open the Actions panel with Option+F9 on the Mac or F9 on the PC. ActionScript code runs one line at a time, in small fractions of a second. In fact, many lines are processed in one frame, which could be 1/60th of a second, or 1/24th of a second. So the code is processed very quickly. Again, the code runs one line at a time, but sometimes, a process will take a little bit longer than another one; for example, loading a PNG file like I'm doing on line 3.

When this happens, instead of waiting for that whole process to be finished, Flash just moves on to the next line and the file loads in the background. This is called asynchronous code. Another thing I want to point out when you're working with ActionScript is some code runs at a specified time, or when a specified event occurs. We're going to be talking about this in more detail later, but for now I want you to understand that some code doesn't run line-by-line.

For example, before the file is loaded, I connect the loading file to a block of code. I tell Flash, when the file is done loading, then I want you to run this block of code called the fileLoaded. That block of code will cause a message to appear in the output window. That's what a trace statement does. It simply allows you to create a note for yourself that will pop up in the Output window while your movie is playing.

It can be used to fix problems in your code. So before I test the movie, I just want to point out that I have these trace statements here to demonstrate in what order the code is processed. So I have the file loading on line 3, and then the trace statement that says started loading file on line 4, so that's after the file starts loading. Once the file is done loading, then you'll see file loaded in the Output window. So I'll test the movie. It says started loading file, and then file loaded after that in the Output window.

So you can see that the file starts loading, and then Flash just moves on to the next line, and when the file is complete, this block of code runs. So what I want you take out of this is I want you to remember that ActionScript code is processing the Flash Player is asynchronous, so commands that take more time to complete, like a loading file, may still be running while Flash moves on to other lines of code, and that some lines of code will be executed when an event occurs.

Understanding how ActionScript 3.0 code is processed in the Flash Player
Video duration: 3m 22s 7h 8m Beginner Updated May 23, 2012

Viewers:

Understanding how ActionScript 3.0 code is processed in the Flash Player 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 ...