MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 53

Actionscript language reference
Table of Contents

Advertisement

Creating properties and methods
A class's members consist of properties (variable declarations) and methods (function definitions).
You must declare and define all properties and methods inside the class body (the curly braces
[{}]); otherwise, an error will occur during compilation.
Any variable declared within a class, but outside a function, is a property of the class. In the
following example, the Person class discussed in
two properties,
age
class Person {
var age:Number;
var name:String;
}
Similarly, any function declared within a class is considered a method of the class. In the Person
class example, you created a single method called
class Person {
var age:Number;
var name:String;
function getInfo():String {
// getInfo() method definition
}
}
The
keyword is not required in ActionScript 2.0 class definitions because the compiler
this
resolves the reference and adds it into the bytecode. However, using
readability..
Controlling member access
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
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:
function LoginClass(user:String) {
this.userName = user;
}
}
and
, of type Number and String, respectively:
name
.
getUserName()
"Using classes: a simple example" on page 48
:
getInfo()
this
or
member attribute. For
public
private
Creating and using classes
has
can improve your code's
and a
userName
53

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents