Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Functions and Methods > About functions and methods > About nested functions | |||
You can call a function from inside another function. This lets you nest functions so that you can have them perform specific tasks in Flash.
For example, you can nest functions on a timeline to perform specific tasks on a string. Type the following code on Frame 1 of the Timeline:
var myStr:String = "My marshmallow chicken is yellow.";
trace("Original string: " + myStr);
function formatText():Void {
changeString("Put chicken in microwave.");
trace("Changed string: " + myStr);
}
function changeString(newtext:String):Void {
myStr = newtext;
}
// Call the function.
formatText();
Select Control > Test Movie to test the nested function. The formatText() and changeString() functions are both applied to the string when you call the formatText() function.
|
|
|
|