ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Polymorphism | 41

implementation. (In Example 1-20 you can see how an interface structure is pro-


grammed to the interface instead of an implementation.)


You will need an FLV file, an MP3 file, and a GIF file for this application. Name the


FLV fileplasma.flv, the MP3 filebongo.mp3, and the GIF filewhizbang.gif. The con-


tents are unimportant but the names and file types are important.


Open a new Flash document, save it in the same folder with the rest of the applica-


tion, and type inDoBusinessin the Document class window. When you test it, the


Output window shows the following:


42 inch TV with Plasma screen
$855

MP3Player with 1 Terabyte of Memory
$245

New 10 gHz processor, 30 gigabyte RAM, includes 32 inch flat screen monitor
$1200

Example 1-36. DoBusiness.as


package
{
import flash.display.Sprite;


public class DoBusiness extends Sprite
{
public function DoBusiness( )
{
//TV
var tv:Plasma=new Plasma( );
trace(tv.productDescribe( ));
trace(tv.productPrice(855));
tv.productDisplay("plasma.flv");
tv.x=160;
tv.y=110;
addChild(tv);


//MP3
var mp3:MP3Player=new MP3Player( );
trace(mp3.productDescribe( ));
trace(mp3.productPrice(245));
mp3.productDisplay("bongo.mp3");


//Computers
var computers:Computers=new Computers( );
trace(computers.productDescribe( ));
trace(computers.productPrice(1200));
computers.productDisplay("whizbang.gif");
addChild(computers);
}
}
}

Free download pdf