Join Todd Perkins for an in-depth discussion in this video Understanding ActionScript 3.0, part of Flash CS4 Professional: Object-Oriented Programming .
In this chapter, we are going to be working with ActionScript 3.0. ActionScript 3.0 works in the Flash Player. That means you will have to test the movie from Flash or publish a SWF file to see the code in action. Before we get started writing ActionScript 3.0 code, make sure you are working with an ActionScript 3.0 file. You can see that in your Publish Settings, in the Properties panel. If you need to change your Publish Settings, you can click the Edit Profile button in the Properties panel and then in the Flash tab adjust the Player version and ActionScript version. I'll click Cancel to close that menu.
Now we will write some ActionScript code. ActionScript can be placed in two places. On keyframes in the Timeline or in external files. The focus of this title is going to be writing external files using object-oriented programming. For quick examples, I'm going to use Timeline code. When you are using Timeline code, you should have a layer named Actions with no art in it. That way your code is organized and easy to find. Let's write some simple ActionScript code and test it in the Flash Player to see it run. Let's select the first keyframe of the Actions layer to write code using the Actions panel. You can find the Actions panel under Window > Actions or by using the keyboard shortcut Option+F9 on the Mac or F9 on the PC.
In the Actions panel, I want you to turn off Script Assist mode. So you shouldn't see any gray space at the top of the panel. I'm mostly going to hide the toolbars on the left side by clicking the Hide button. One of the essential ActionScript statements is a trace statement. That's a function that's built into the Flash Player that you can call anywhere. So it's what's called a global function. This can be used to debug your code. What happens when the Flash movie runs and this line of code is reached, is a message appears in Flash's Output window. So you can use it to make sure the code is running properly. To use a trace statement, type the word trace and trace is actually a function. So I can type some parenthesis, which is what you use in Flash to run a function, a semicolon to end the statement and then I'm going to pass in a string into the parenthesis. So I'm going to type some quotes and in the quotes, I'm going to type Hello from ActionScript.
I will test the movie using Command+ Return on the Mac or Ctrl+Enter on the PC and watch the message appear in the Output window. I'll close the Preview window and return to the code. So to recap, ActionScript code runs in the Flash Player. It can be placed in the Timeline or in external class files, and this code we used here is a trace statement, which makes the message appear in the Output window.
- Loading external text, images, and XML files
- Creating essential properties for a View class
- Defining a Model class
- Building and implementing interfaces and designs
- Debugging projects
- Building applications with Controller-class buttons
Skill Level Intermediate
1. ActionScript 3.0 Essentials
2. Advanced ActionScript Techniques
3. Object-Oriented Programming Fundamentals
4. The Model View Controller Design Pattern
5. Building a Model Class
6. Building a View Class
7. Building a Controller Class
8. Improving and Debugging the Application
9. Moving Forward
- 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.