Join Todd Perkins for an in-depth discussion in this video Understanding trace statements, part of ActionScript 3.0 in Flash CS4 Professional for Designers.
When you are creating ActionScript applications, you'll often find the need to test your code at a certain point. When you need to do that, one of the best ways is something called Trace Statements. In this movie we'll be looking at how to write Trace Statements in ActionScript. If you are following along, open up Trace.fla or just create a blank file. Let's go to the first keyframe of the Actions layer and open up the Actions panel with Option+F9 on the Mac, or F9 on the PC. In the Actions panel, I am going to create the Trace Statement by typing the word trace, all lowercase. Just type trace. It should turn in blue after you type it. And again, it's all lowercase. Type ();. The Trace Statement makes a message appear in the Output window. The message that appears depends on what you put inside of the parenthesis. So put your cursor inside the parenthesis, and I want you to type two quotes. Quotes are used to identify something in ActionScript called Strings. Basically Strings refer to text. So if you wanted to put some kind of text value in Output window, you can put that value inside of the quotes.
So in the quotes, I am going to put "hello from ActionScript!" You can type any message you like. It's going to work fine provided that you write it inside of the quotes. Also something to note right now, that Strings in Flash are green. Let's test the movie to see the application in action and that's Cmd+Return on the Mac, Ctrl+Enter on the PC. If I move the Preview window over, then I will see 'hello from ActionScript!' in the Output window. Close the Preview Window and return to your quote.
So using Trace Statements, you can easily make notes to yourself or test to see that codes working properly in the Output window. All you have to do to write a Trace Statement is use the word trace, all lowercase, type some parenthesis, and then a semicolon, and by the way a semicolon is an ActionScript way of ending a statement, just like a period in the sentence. Then type the message to yourself in the parenthesis. If you want to have it be a text based message, put that message in quotes.
- Working with loops to show repeated actions
- Defining functions and variables
- Handling events and event listeners
- Using classes to organize code
- Building arrays to hold lists of information
- Loading external content from various files
- Adding images and sound to an application
Skill Level Intermediate
Q: After creating a preloader as shown in the "Creating a preloader" movie, an error message reading "Error #1009: Cannot access a property or method of a null object reference" appears when the preloader is placed in the timeline. How can this issue be resolved?
A: There is most likely a typo in the code. Unfortunately, Error 1009 is the most vague error in Flash and means the code trying to reference an object that doesn't exist (hence the likeliness of a typo). The best fix is to go through the code one character at a time to make sure everything is correct.
1. Introducing AS3.0 Fundamentals
2. Working with Variables
3. Using Functions
4. Working with Display Objects
5. Understanding and Handling Events
6. Creating Conditional Statements
7. Using Math to Perform Tasks
8. Creating and Using Arrays
9. Creating and Using Loops
10. Using Classes
11. Handling Text
12. Loading Media
13. Creating a Calculator
14. Getting Out of Trouble
Getting help3m 26s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.