Understanding Methods - MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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
functions are both applied to the string when you call the
changeString()
function.

Understanding methods

Methods are functions that are associated with a class. The class could be a custom class or
built-in classes that are part of the ActionScript language. For information on comparing
methods to functions, see
methods and functions" on page
For example,
sortOn()
function of the predefined Array class built into Flash).
To use the sortOn() method in a FLA file:
1.
Create a new Flash document and save it as methods.fla.
2.
Add the following code to Frame 1 of the Timeline:
var userArr:Array = new Array();
userArr.push({firstname:"George", age:39});
userArr.push({firstname:"Dan", age:43});
userArr.push({firstname:"Socks", age:2});
userArr.sortOn("firstname");
var userArrayLenth:Number = userArr.length;
var i:Number;
for (i = 0; i < userArrayLenth; i++) {
trace(userArr[i].firstname);
}
222
Functions and Methods
"About functions and methods" on page 201
203.
is a built-in method associated with the Array class (
and
formatText()
formatText()
and
"About types of
sortOn
is a

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents