EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 257

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About working with custom classes in an application 257
3. Save the ActionScript document as Login.as.
As you can see,
getUserName() returns the current value of userName, and
setUserName() sets the value of userName to the string parameter passed to the method.
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
get and set method attributes. You create methods that get
or set the value of a property, and add the keyword
get or set before the method name, as
shown in the next example.
NOTE
Implicit getter and setter methods are syntactic shorthand for the Object.addProperty()
method found in ActionScript 1.0.

Table of Contents

Related product manuals