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.ht= "<b>Mammal\tGender\tSleep\tPlay</b>";
for (i = 0; i < len; i++) {
info_txt.ht= "<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.ht= "</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]
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...