10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Examples 1-45 though 1-54 make up the application. Save all the .as files in the<br />

same folder. It represents a typical use of <strong>com</strong>position.<br />

Example 1-45. Media.as<br />

package<br />

{<br />

//Abstract class<br />

class Media<br />

{<br />

//Composition: Reference to two interfaces<br />

var playMedia:PlayMedia;<br />

var recordMedia:RecordMedia;<br />

}<br />

}<br />

public function Media( ) {}<br />

public function doPlayMedia( ):void<br />

{<br />

//Delegates to PlayMedia<br />

playMedia.playNow( );<br />

}<br />

public function doRecordMedia( ):void<br />

{<br />

//Delegates to RecordMedia<br />

recordMedia.recordNow( );<br />

}<br />

Example 1-46. VideoFlash.as<br />

package<br />

{<br />

//Concrete Media subclass: Video<br />

class VideoFlash extends Media<br />

{<br />

public function VideoFlash( )<br />

{<br />

//Inherits <strong>com</strong>position references from superclass<br />

playMedia = new PlayVideo( );<br />

recordMedia = new RecordVideo( );<br />

}<br />

}<br />

}<br />

Example 1-47. Mp3.as<br />

package<br />

{<br />

//Concrete Media subclass: Audio<br />

public class Mp3 extends Media<br />

{<br />

Favor Composition | 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!