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

Chapter 5. Using Functions > USING LOCAL VARIABLES AND CREATING FUNCTIONS THAT ...

USING LOCAL VARIABLES AND CREATING FUNCTIONS THAT RETURN RESULTS

The variables you’ve created and used thus far can be accessed at any time by any script in the Flash movie. In contrast, local variables are special variables that you can only create and use within the scope of a function definition. In other words, a local variable is created within the function definition, used by the function when it’s called, then deleted when that function has finished executing. Local variables exist only within the function definitions where they were created.

Although local variables are not absolutely required in ActionScripting, it’s good programming practice to use them. Applications that require many and frequent calculations end up creating a lot of variables—which can slow applications. By using local variables, however, you minimize memory usage. And by employing them in function definitions, you also help prevent naming collisions—which occur when your project gets so big that you unknowingly create and use variable names that are already in use. However, local variables in one function definition can have the same names as local variables within another function definition—even if both definitions exist on the same timeline. This is because Flash understands that a local variable only has meaning within the function definition where it was created.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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