Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 93637 Viewers
82 Video lessons · 104409 Viewers
71 Video lessons · 76598 Viewers
56 Video lessons · 107921 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.