ActionScript 3.0 Design Patterns

(Chris Devlin) #1

14 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0


All the values for the different elements (with the exception of null) have been


abstracted to describethe object. However, like a job description that abstracts


requirements, so too does thePlayVideoAbstractclass. All the particulars have been


placed into one long set of parameters:


PlayVideoAbstract(nc:NetConnection,ns:NetStream,vid:Video,flick:String,
xpos:uint,ypos:uint)

The abstract parameters in the constructor function let us add any concrete ele-


ments we want, including the specific name of a video we want to play. Example 1-4


shows how concrete instances are implemented from an abstract class.


All the entire class does is to create a single instance of thePlayVideoAbstractclass


and place it on the stage. Private variables serve to provide most of the concrete val-


ues for the required parameters. Literals provide the data for both the horizontal (x)


and vertical (y) positions of the video. To test it, just change the Document class


name in the Flash document (FLA) file toPlayAbstract.


}

}

Example 1-4. PlayAbstract.as


package
{
import flash.display.Sprite
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;


public class PlayAbstract extends Sprite
{
private var conn:NetConnection;
private var stream:NetStream;
private var vid:Video;
private var flick:String="adp.flv";


public function PlayAbstract( )
{
var playIt:PlayVideoAbstract=new PlayVideoAbstract(conn,stream,vid,
flick,100,50);
addChild(playIt);
}
}
}


Example 1-3. PlayVideoAbstract.as (continued)

Free download pdf