ActionScript Fundamentals pt. 2 / Writing Custom Classes
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Perhaps the best way to understand the use of classes in an object-oriented language like ActionScript 3.0 is to start creating your own custom classes from scratch. So let me demonstrate this technique in this movie. First, save a new file with the .AS file extension. Make sure the file name matches the name of the class. In our previous example, the name of the class was Jukebox underscore Method. So notice that this file is named that. You'll just simply do File, New and then from the ActionScript File Option, click on OK and then when naming it, File, Save As, make sure you're naming it the name of the new custom class. I've already done that so let's close this script file. Next add the package name and then the class definition to the file with the structure you see here: package open curly brace. In this case I'm importing the Flash display, the movie clip here and then I'm extending that movie clip with my public class definition right there but that's the important part; public class, then the name of the class. Let's change that back to method right there, make sure that is the same as the file name. This line right here is declaring the class itself. You can also just put public class and then the name of the class. The name of the class starts with a capital letter by convention but in this case I wanted to keep everything lowercase since I've been really bugging you and hammering home the idea of not using uppercase letters but when naming these custom classes, the convention is to name the package with the lowercase letter and the custom classes starting with an uppercase letter. The name of the class must follow the same naming rules as variables and functions. In other words, it must consist of letters, numbers and underscores and cannot start with a number. The class declaration appears within the package declaration. Notice in this case the package declaration is in between these sets of curly braces; this one here and this one down here. Now, the class body appears within the classes declaration curly braces. In this case there's the opening curly brace. Here is the closing curly brace so my class definition is this part right here in the example previous. It'll consist of properties and methods; in this case custom methods. Properties are variables associated with the class and you can declare them much as you would declare variables by using the v-a-r keyword right here; private variable play status Boolean. Here's another example of a custom class that I got from the Internet using Google. Here's the public class Zoomer. This time it extends the sprite class private variable there defining various functions, defining what the custom class will be. In this case this is a pretty detailed and extended custom class. These are the kind of custom classes that you'll find on the Internet that you can cut and paste into your own ActionScript file. And then again, calling them as I demonstrated in the previous movie using this import action in your actual fla file, calling for the use of this custom class. So there you have a few movies reviewing the uses of custom classes that other people have created and also how to create your own simple custom classes. That'll conclude this section of the tutorial reviewing some ActionScript fundamentals Part 2 of ActionScript fundamentals in this section of the tutorial. You revisited variables, learned about constants and conditional statements. You've learned about for loops, while loops, arrays, how to write custom methods and how to use them and how to use and write custom classes.
Tutorial Information
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 