ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Abstraction | 13

You’ll need an FLV file namedadp.flv—any FLV file with that name will work. Open


a new Flash document file, enterPlayVideo in the Document class window, and test it.


To change this to an abstract file, take out all specific references to any values with


the exception of thenullvalue in theNetConnection.connect( )method. (We could


pass that value as a string, but we’re leaving it to keep things simple.) Example 1-3


shows essentially the same application abstracted to a “description” of what it


requires to work.


{

public function PlayVideo( )
{
var nc:NetConnection=new NetConnection( );
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var vid:Video=new Video( );
vid.attachNetStream(ns);
ns.play("adp.flv");
addChild(vid);
vid.x=100;
vid.y=50;
}
}
}


Example 1-3. PlayVideoAbstract.as


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


public class PlayVideoAbstract extends Sprite
{
public function PlayVideoAbstract(nc:NetConnection,
ns:NetStream,vid:Video,flick:String,xpos:uint,ypos:uint)
{
nc=new NetConnection( );
nc.connect(null);
ns= new NetStream(nc);
vid=new Video( );
vid.attachNetStream(ns);
ns.play(flick);
vid.x=xpos;
vid.y=ypos;
addChild(vid);
}


Example 1-2. PlayVideo.as (continued)

Free download pdf