
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
330
|
Chapter 13: MovieClip Subclasses
Nested Assets Not Automatically Recognized by Compiler
Assets nested in a movie clip symbol are not automatically available to a correspond-
ing MovieClip subclass as instance properties. That is, a MovieClip subclass cannot
refer to assets nested inside its associated movie clip symbol unless the subclass
explicitly declares those assets as instance properties.
For example, consider a LoginSymbol movie clip symbol that contains two text
fields,
userName and password. The LoginSymbol’s corresponding MovieClip subclass
is Login. The Login class wants to set the default contents of the
userName and
password text fields. If we use the following Login class code:
class Login extends MovieClip {
public function Login ( ) {
userName.text = "Enter your name.";
password.text = "Enter your password.";
}
}
the compiler generates the following errors:
There is no property with the name 'userName'.
userName.text = "Enter your name.";
There is no property with the name 'password'.
password.text = "Enter your password.";
We know that the LoginSymbol movie clip symbol contains the required text fields,
but the compiler doesn’t have any way of knowing. The compiler bases its type
checking on the Login class definition, not the contents of the LoginSymbol movie
clip