EasyManua.ls Logo

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

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...
312 Inheritance
14. In mammalTest.fla, type the following ActionScript code into Frame 1 of the
main Timeline:
var mammals_arr:Array = new Array();
this.createTextField("info_txt", 10, 10, 10, 450, 80);
info_txt.html = true;
info_txt.multiline = true;
info_txt.border = true;
info_txt.wordWrap = true;
createMammals()
createReport()
function createMammals():Void {
mammals_arr.push(new Dog("Female"));
mammals_arr.push(new Cat("Male"));
mammals_arr.push(new Monkey("Female"));
mammals_arr.push(new Mammal("Male"));
}
function createReport():Void {
var i:Number;
var len:Number = mammals_arr.length;
// Display Mammal info in 4 columns of HTML text using tab stops.
info_txt.htmlText = "<textformat tabstops='[110, 200, 300]'>";
info_txt.htmlText += "<b>Mammal\tGender\tSleep\tPlay</b>";
for (i = 0; i < len; i++) {
info_txt.htmlText += "<p>" + mammals_arr[i].speciesName
+ "\t" + mammals_arr[i].gender
+ "\t" + mammals_arr[i].sleep()
+ "\t" + mammals_arr[i].play() + "</p>";
// The trace statement calls the Mammal.toString() method.
trace(mammals_arr[i]);
}
info_txt.htmlText += "</textformat>";
}
The mammalTest.fla code is a bit more complex than the previous classes. First it imports
the three animal classes.
15. Save the Flash document, and then select Control > Test Movie to test the document.
You see the Mammal information displayed in a text field on the Stage, and the following
text in the Output panel:
[object Dog]
[object Cat]
[object Monkey]
[object Mammal]

Table of Contents

Related product manuals