
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Recursive Functions
|
203
Note that new values assigned to individual elements of the array from inside a func-
tion are reflected outside the function as well. However, suppose that instead of
assigning new values to one or more elements, we assign a new value to the parame-
ter itself. Doing so will break its association with the original argument. Subsequent
changes to the parameter variable will have no effect on the original argument, as
shown in Example 9-7. In this example, although the
boys array is passed as an argu-
ment, the myArray parameter variable is immediately set to girls. Subsequent
changes to
myArray affect the girls array, not the boys array.
More information on primitive and composite data can be found in Chapter 3.
Recursive Functions
A recursive function is a function that calls itself (by using its own name within its
function body). Here’s a simple example that shows the principle of recursion. But
because the code tells the trouble() function to execute repeatedly (like an image
reflected infinitely in two opposing mirrors), Flash will quickly exceed its maximum
recursion limits, causing an error:
function trouble () {
trouble();
}
// Pass our array to the function
setValue(boys);
// Check the value of our array elements
trace("Boys: " + boys); // Displays: "Boys: Sid,Graham,Derek" ...