O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Composition-Based Alternative to Linked Classes

In this chapter, we've learned to add behavior to Movie Clip symbols by linking them to custom classes. As an alternative practice, to give programmatic behavior to a symbol we can simply create an instance of any custom class on the symbol's timeline and then use that instance to control the symbol.

For example, in the preceding section, we associated the login form symbols with the LoginForm class in order to give the symbols the programmatic ability to submit information to a server. But arguably, the LoginForm class is not a subtype of MovieClip. It is, rather, a simple communication utility that happens to take input from a user interface. As such, it can be (and perhaps should be) defined as a stand-alone class for use by any symbol that agrees to provide the appropriate inputs.

For the sake of comparison, the following code shows a new version of the LoginForm class, revised for use as a helper class on a symbol's timeline. The new class has a new name, LoginManager, reflecting its new role as a communication utility class. Notice that the new class constructor expects references to user interface objects that will supply user input.

package { import flash.display.*; import flash.text.*; import flash.events.*; public class LoginManager { private var username:TextField; private var password:TextField; public function LoginManager (username:TextField, password:TextField, submitBtn:SimpleButton) { this.username = username; this.password ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required