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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 1-2. PlayVideo.as (continued)<br />

}<br />

{<br />

}<br />

public function PlayVideo( )<br />

{<br />

var nc:NetConnection=new NetConnection( );<br />

nc.connect(null);<br />

var ns:NetStream = new NetStream(nc);<br />

var vid:Video=new Video( );<br />

vid.attachNetStream(ns);<br />

ns.play("adp.flv");<br />

addChild(vid);<br />

vid.x=100;<br />

vid.y=50;<br />

}<br />

You’ll need an FLV file named adp.flv—any FLV file with that name will work. Open<br />

a new Flash document file, enter PlayVideo in the Document class window, and test it.<br />

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

the exception of the null value in the NetConnection.connect( ) method. (We could<br />

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

shows essentially the same application abstracted to a “description” of what it<br />

requires to work.<br />

Example 1-3. PlayVideoAbstract.as<br />

package<br />

{<br />

import flash.net.NetConnection;<br />

import flash.net.NetStream;<br />

import flash.media.Video;<br />

import flash.display.Sprite;<br />

public class PlayVideoAbstract extends Sprite<br />

{<br />

public function PlayVideoAbstract(nc:NetConnection,<br />

ns:NetStream,vid:Video,flick:String,xpos:uint,ypos:uint)<br />

{<br />

nc=new NetConnection( );<br />

nc.connect(null);<br />

ns= new NetStream(nc);<br />

vid=new Video( );<br />

vid.attachNetStream(ns);<br />

ns.play(flick);<br />

vid.x=xpos;<br />

vid.y=ypos;<br />

addChild(vid);<br />

}<br />

Abstraction | 13

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

Saved successfully!

Ooh no, something went wrong!