804
Appendix E: Object-Oriented Programming with ActionScript 1
Instead of adding
roll()
to the MountainBike class and the Tricycle class, you can create the
MountainBike class with Bike as its superclass:
MountainBike.prototype = new Bike();
Now you can call the
roll()
method of MountainBike, as shown in the following:
MountainBike.roll();
Movie clips do not inherit from each other. To create inheritance with movie clips, you can use
Object.registerClass()
to assign a class other than the MovieClip class to movie clips. See
Object.registerClass()
in
Chapter 12, “ActionScript Dictionary,” on page 205
.
For more information on inheritance, see the
Object.__proto__
,
#initclip
,
#endinitclip
,
and
super
entries in
Chapter 12, “ActionScript Dictionary,” on page 205
.
Adding getter/setter properties to objects in ActionScript 1
You can create getter/setter properties for an object using the
Object.addProperty()
method.
A getter function is a function with no parameters. Its return value can be of any type. Its type can
change between invocations. The return value is treated as the current value of the property. A
setter function is a function that takes one parameter, which is the new value of the property. For
instance, if property x is assigned by the statement x = 1, the setter function is passed the
parameter 1 of type Number. The return value of the setter function is ignored.
When Flash reads a getter/setter property, it invokes the getter function, and the function’s return
value becomes a value of
prop
. When Flash writes a getter/setter property, it invokes the setter
function and passes it the new value as a parameter. If a property with the given name already
exists, the new property overwrites it.
You can add getter/setter properties to prototype objects. If you add a getter/setter property to a
prototype object, all object instances that inherit the prototype object inherit the getter/setter
property. This makes it possible to add a getter/setter property in one location, the prototype
object, and have it propagate to all instances of a class (much like adding methods to prototype
objects). If a getter/setter function is invoked for a getter/setter property in an inherited prototype
object, the reference passed to the getter/setter function will be the originally referenced object,
not the prototype object.
For more information, see
Object.addProperty()
in
Chapter 12, “ActionScript Dictionary,”
on page 205
.
The Debug > List Variables command in test mode supports getter/setter properties that you add
to objects using
Object.addProperty()
. Properties that you add to an object in this way are
displayed alongside other properties of the object in the Output panel. Getter/setter properties are
identified in the Output panel with the prefix
[getter/setter]
. For more information on the
List Variables command, see
“Using the Output panel” on page 77
.
Using Function object properties in ActionScript 1
You can specify the object that a function is applied to and the parameter values that are passed to
the function, using the
call()
and
apply()
methods of the Function object. Every function in
ActionScript is represented by a Function object, so all functions support
call()
and
apply()
.
When you create a custom class using a constructor function, or when you define methods for a
custom class using a function, you can invoke
call()
and
apply()
for the function.
Содержание FLASH MX 2004 - ACTIONSCRIPT
Страница 1: ...ActionScript Reference Guide...
Страница 8: ...8 Contents...
Страница 12: ......
Страница 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Страница 54: ...54 Chapter 2 ActionScript Basics...
Страница 80: ...80 Chapter 3 Writing and Debugging Scripts...
Страница 82: ......
Страница 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Страница 112: ......
Страница 120: ...120 Chapter 6 Using the Built In Classes...
Страница 176: ......
Страница 192: ...192 Chapter 10 Working with External Data...
Страница 202: ...202 Chapter 11 Working with External Media...
Страница 204: ......
Страница 782: ...782 Chapter 12 ActionScript Dictionary...
Страница 793: ...Other keys 793 221 222 Key Key code...
Страница 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Страница 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Страница 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Страница 816: ...816 Index...