Figure 7-3. Instantiation of the class Dog
Methods
When we talk about methods in ActionScript, we essentially are talking about functions. These functions
are encapsulated pieces of code that do a specific task and may or may not return a value after
doing these actions.
You identify these encapsulated pieces of code with the word function followed by the method
name, and enclose whatever action you want to create within braces ({}). Let??™s expand on the Dog
class by adding a method named bark(), which will simulate our Dog barking (Figure 7-4).
The word public is the access modifier. We will be discussing this a bit later in this chapter, but for the
moment simply assume that it needs to be there.
Figure 7-4. The bark() method
When we call this function, it immediately executes the line trace("woof! woof!");. trace is a command
in ActionScript that helps debug your applications by printing information to the console in Flex when you
click the Debug button.
Methods are very important because they constitute the body of a class. They work as small pieces of
code that break the functionality of a class into manageable pieces.
As I mentioned earlier, a function may or may not return a value after it finishes executing its task. In
our case, we are not returning a value of any kind. We denote this with a colon and the word void
139
ACTIONSCRIPT IN FLEX
right after the closing parenthesis after the function name. However, functions can also take in values,
process those values, and return a new value.
Pages:
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110