Functions in AS 3.0
Functions are reusable blocks of code stored under a name, that are easy to be called back in Action Scripting.
The first time you introduce a function in a piece of code,
you need to DECLARE the new function, including: the word function, the name of the function, the parenthesis (that holds the event ype or the parameters) and the data type.
function |
goStep2 | (Event:MouseEvent) | : void | { |
function |
name | event type | data type | { |
gotoAndPlay |
("part 2") | } |
method |
parameter | close |
A more complex function, of a differnt type and with parameters would look like this:
(notice that the parameters are variables)
function |
myFunction | ( | myNumber:Number | , | myString:String | ) | :Boolean | { |
function |
name | ( | parameter | , | parameter | ) | data type | { |
if |
( | myNumber | == | 7 | ) | return true | ; |
conditional |
( | parameter | operator | numb | ) | ; |
if |
( | myString | . | length | ) | return true | ; |
conditional |
( | parameter | dot | property | ) | ; |
return false | ; | |
boolean return |