EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 217

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About functions and methods 217
return Number.NaN;
}
num_array.sort(Array.NUMERIC | Array.DESCENDING);
var min:Number = Number(num_array.pop());
return min;
}
public static function arrayMax(num_array:Array):Number {
if (num_array.length == 0) {
return undefined;
}
num_array.sort(Array.NUMERIC);
var max:Number = Number(num_array.pop());
return max;
}
}
3.
Select File > Save to save the ActionScript file.
4. Create a new Flash document and save it as classFunctions.fla in the same directory
as Utils.as.
5. Select Window > Actions to open the Actions panel.
6. Type the following ActionScript into the Script pane:
var randomMonth:Number = Utils.randomRange(0, 11);
var min:Number = Utils.arrayMin([3, 3, 5, 34, 2, 1, 1, -3]);
var max:Number = Utils.arrayMax([3, 3, 5, 34, 2, 1, 1, -3]);
trace("month: " + randomMonth);
trace("min: " + min); // -3
trace("max: " + max); // 34
7.
Select Control > Test Movie to test the documents. The following text is displayed in the
Output panel:
month: 7
min: -3
max: 34
NOTE
For information on writing code using Script Assist, see “Using Script Assist to write
ActionScript” on page 328, “Creating a startDrag/stopDrag event using Script
Assist” on page 331 and the ActionScript:Use Script Assist Mode tutorial (which
begins with “Open the starter document” on page 213).

Table of Contents

Related product manuals