MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 273

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

Controlling member access in your classes
By default, any property or method of a class can be accessed by any other class: all members
of a class are public by default. However, in some cases you might want to protect data or
methods of a class from access by other classes. You need to make those members private
(available only to the class that declares or defines them).
You specify public or private members using the public or private member attribute. For
example, the following code declares a private variable (a property) and a private method (a
function). The following class (LoginClass) defines a private property named
private method named
class LoginClass {
private var userName:String;
private function getUserName():String {
return this.userName;
}
// Constructor:
public function LoginClass(user:String) {
this.userName = user;
}
}
Private members (properties and methods) are accessible only to the class that defines those
members and to subclasses of that original class. Instances of the original class, or instances of
subclasses of that class, cannot access privately declared properties and methods; that is,
private members are accessible only within class definitions, not at the instance level. In the
following example, you change member access in your class files.
This exercise is part of
wish to progress through the example, you can download the class files from
www.helpexamples.com/flash/learnas/classes/.
To control member access:
1.
Open ClassA.as and ClassB.as in the Flash authoring tool.
2.
Modify the ClassA.as ActionScript file so its contents match the following ActionScript
(the changes to make appear in boldface):
class com.macromedia.utils.ClassA {
private static var _className:String = "ClassA";
public function ClassA() {
trace("ClassA constructor");
}
public function doSomething():Void {
trace("ClassA - doSomething()");
}
}
:
getUserName()
"Example: Writing custom classes" on page
userName
263. If you do not
Example: Writing custom classes
and a
273

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents