• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 14. Extending ActionScript > Registering Custom Classes

Registering Custom Classes

Although we looked at a lot of theory and practical uses for homemade objects in the last chapter, the topic of registering custom classes fits well in this chapter. In fact, any time that you create a constructor function, you’re really defining a class. However, homemade objects (despite being a lot of fun) are never visualized unless you take steps to affect onscreen clips and text. That is, an object is simply stored in a variable but you don’t see anything unless you (by hand) tie it to something onscreen. In fact, no instances of your homemade object (class) exist unless you instantiate them.

The new registerClass() method makes it possible to create a class (or definition of your homemade object) that automatically inherits all the features of the built-in Movie Clip class. At the same time, you associate a particular symbol with your class so that every time that symbol is instantiated (dragged out of the Library), you’ll be instantiating an object of the homemade class. This means you can design a homemade object that is automatically linked to something visual—and it will behave just like the parent object but with additional methods and properties that you define. For example, you can make a Button class that is just like any other button clip, but which automatically displays a checkmark that toggles on and off. We’ll do just that. Not only will the onPress event trigger a callback to display or remove the checkmark graphic, but onPress will also trigger any other function you want—and that function can be different for each instance of the button. That is, we’ll effectively get around the fact that one button can have only one onPress event callback. If it sounds to you like the “super button” we’re going to create is sort of like a component, you’re right. The point is, the registerClass() method is an integral part of how components can supplement your movies without conflicting what’s already present.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint