8.
Save your changes to the person2_test.fla file.
9.
Select Control > Test Movie to test the code.
Because the custom Flash class is dynamic, you can add methods and properties to the
class at runtime (when the SWF file plays). When you test the code the text
be displayed in the Output panel.
When you develop applications, you wouldn't want to make classes dynamic unless you
needed to. One reason not to use dynamic classes is that type checking on dynamic classes is
less strict than type checking on nondynamic classes, because members accessed inside the
class definition and on class instances are not compared with those defined in the class
scope. Class member functions, however, can still be type checked for return types and
parameter types.
Subclasses of dynamic classes are also dynamic, with one exception. Subclasses of the
MovieClip class are not dynamic by default, even though the MovieClip class itself is
dynamic. This implementation provides you with more control over subclasses of the
MovieClip class, because you can choose to make your subclasses dynamic or not:
class A extends MovieClip {}
dynamic class B extends A {}
class C extends B {}
class D extends A {}
dynamic class E extends MovieClip{} // E is dynamic
For information on subclasses, see
About using encapsulation
In elegant object-oriented design, objects are seen as "black boxes" that contain, or
encapsulate, functionality. A programmer should be able to interact with an object by knowing
only its properties, methods, and events (its programming interface), without knowing the
details of its implementation. This approach enables programmers to think at higher levels of
abstraction and provides an organizing framework for building complex systems.
Encapsulation is why ActionScript 2.0 includes, for example, member access control, so that
details of the implementation can be made private and invisible to code outside an object.
The code outside the object is forced to interact with the object's programming interface
rather than with the implementation details. This approach provides some important
benefits; for example, it lets the creator of the object change the object's implementation
without requiring any changes to code outside of the object, as long as the programming
interface doesn't change.
// A is not dynamic
// B is dynamic
// C is dynamic
// D is not dynamic
Chapter 8, "Inheritance," on page
About working with custom classes in an application
should
blue
301.
261
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?