3.
Save the ActionScript document as Login.as.
As you can see,
getUserName()
sets the value of
setUserName()
4.
Select File > New and then select Flash Document to create a new FLA, and save it as
login_test.fla in the same directory as Login.as.
5.
Add the following ActionScript to Frame 1 of the main Timeline:
var user:Login = new Login("RickyM");
// calling getUserName() method
var userName:String = user.getUserName();
trace(userName); // RickyM
// calling setUserName() method
user.setUserName("EnriqueI");
trace(user.getUserName()); // EnriqueI
6.
Select Control > Test Movie to test the file.
Flash displays the following information in the Output panel:
RickyM
EnriqueI
However, if you want to use a more concise syntax, you can use implicit getter and setter
methods. Implicit getter and setter methods let you access class properties in a direct manner,
while maintaining good OOP practice.
To define these methods, use the
or set the value of a property, and add the keyword
shown in the next example.
Implicit getter and setter methods are syntactic shorthand for the
method found in ActionScript 1.0.
returns the current value of
to the string parameter passed to the method.
userName
and
method attributes. You create methods that get
get
set
get
About working with custom classes in an application
, and
userName
or
before the method name, as
set
Object.addProperty()
257
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?