Keep in mind that all methods you create must have a return type, even if your function is not
intended to return any value, as in our example. You define a return type after the function name, also
known in programming lingo as a function??™s signature. If you forget, Flex Builder will highlight this as
a compile-time error and will not compile properly.
It is worth mentioning that any variables you declare inside a function are created and destroyed
immediately after the function is done executing.
For example, we are going to teach our Dog how to add by telling him two values and making him tell
us the result. To achieve this, create the function shown in Figure 7-5.
Figure 7-5. The sum() method
Notice inside the parentheses our function expects two values of type Number. We must tell the function
what sort of value to expect. Also, our function includes Number after the colon, which means that
this function returns a new value and that it is of the numerical type. Finally, return is there to tell the
function to send back the result of our sum.
Just as you cannot go without specifying a function??™s return type (unless you use void), you will need
to use the return statement in the method itself.
Access modifiers
Access modifiers might sound very alien, but they are just a set of keywords that you use when creating
packages, classes, functions, and variables to control how they are accessed. These keywords are as
follows:
public means the class can be accessed openly and without restrictions.
Pages:
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111