Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 120

Programming actionscript 3.0
Table of Contents

Advertisement

{
return this;
}
}
var myTest:ThisTest = new ThisTest();
trace(myTest.thisValue() == myTest); // true
Inheritance of instance methods can be controlled with the keywords
You can use the
override
to prevent subclasses from overriding a method. For more information, see
methods" on page
134.
Get and set accessor methods
Get and set accessor functions, also called getters and setters, allow you to adhere to the
programming principles of information hiding and encapsulation while providing an easy-to-
use programming interface for the classes that you create. Get and set functions allow you to
keep your class properties private to the class, but allow users of your class to access those
properties as if they were accessing a class variable instead of calling a class method.
The advantage of this approach is that it allows you to avoid the traditional accessor functions
with unwieldy names, such as
advantage of getters and setters is that you can avoid having two public-facing functions for
each property that allows both read and write access.
The following example class, named GetSet, includes get and set accessor functions named
that provide access to the private variable named
publicAccess()
class GetSet
{
private var privateProperty:String;
public function get publicAccess():String
{
return privateProperty;
}
public function set publicAccess(setValue:String):void
{
privateProperty = setValue;
}
}
If you attempt to access the property
follows:
var myGetSet:GetSet = new GetSet();
trace(myGetSet.privateProperty); // error occurs
120
Object-Oriented Programming in ActionScript
attribute to redefine an inherited method, and the
getPropertyName()
privateProperty
override
and
setPropertyName()
privateProperty
directly, an error will result, as
and
.
final
attribute
final
"Overriding
. Another
:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents