Join Todd Perkins for an in-depth discussion in this video Reading and solving errors through the Compiler Errors window, part of ActionScript 3.0 in Flash Professional CS5 Essential Training.
- View Offline
Even the most seasoned programmers make mistakes, but the difference between the pros and amateurs is that the pros know how to read error messages. Flash has two windows that help you find errors in your code, one of which we'll focus on in this movie. If I test the movie here with Command+ Return or Ctrl+Enter on the PC, you'll see an error in the Compiler Errors window. In the Location section, Flash tells me where the offending code is: in Scene 1, layer 'actions', Line 8.
The description says, Syntax error: expecting rightparen before semicolon. So note that when you get an error, make sure to read the error message. I know that's pretty obvious to say, but read it and really think about what's wrong. There is a missing rightparen, according to Flash. So I am going to double-click this error message, and Flash will actually open up the Actions panel and highlight the offending code for me. Now at this point if you don't understand this code, I don't want you to worry about that. I just want you to understand how the Compiler Errors window works right now.
The offending code is highlighted. I can see at the end that there is only one right parenthesis, but at the beginning of the code there are two left parentheses. So when you are writing ActionScript, they actually need to be balanced out. You need to have - if you have two left parentheses you need to have two right parentheses. One of these on the left is actually a mistake, so if I delete that, I can test the movie again, and Flash has actually given me another error. Note that when you get into Compiler Error, Flash actually stops processing the code.
That's why we didn't see these two errors at once. So if we look at this, we have Scene 1, layer 'actions', Frame 1, Line 23. Access of undefined property SoundMixe. So if I double-click that, I can see that this is undefined, SoundMixe. Now being used to writing code all the time, I know that this is probably supposed to be SoundMixer, with an r on the end, and if you are new and you didn't see that right-away, I promise as you go through this title, as you get more experience with ActionScript, errors like this will become more obvious to you.
So I make the fix, and I test the movie one more time, and the code is processed, and you can tell that by hearing the background music. When you see errors in the Output and Compiler Errors windows, don't panic. Remember that those windows give you important messages about fixing your problems. By paying attention to those messages, you will be able to fix your errors and more quickly transition into being an ActionScript master.
- Understanding the building blocks of ActionScript
- Working with the display list
- Using dot syntax
- Navigating the Timeline
- Creating document classes
- Linking classes to Library objects
- Adding drag/drop functionality to objects
- Creating a slide show
- Loading and running code in an external SWF
- Working with text
- Accessing XML data
- Playing audio and video with ActionScript