• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 20. Basic ActionScript > Combining Statements into Functions

Combining Statements into Functions

A function is an entire block of code that you can call, or invoke, from anywhere in a program. Calling the function causes the code in the function to execute. You can call a function using its name, if it has one. You can also call functions via variables, array elements, or object properties. All these ways of referring to a function are much more concise than the body of the function itself. These ways of referring to functions give you short, convenient “handles” for potentially complex behaviors.

Functions make it much easier to maintain programs. For instance, suppose you create a displayError() function to display error messages. If you ever want to change your error display function, you can make the change in only one place, in the displayError() function declaration. If instead you repeat a block of code multiple times, you have to edit each duplicate block individually.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint