13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

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.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with video<br />

Ext<strong>en</strong>d the NetStream class and make it dynamic<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

You can ext<strong>en</strong>d the NetStream class and make the subclass dynamic so that onCuePoint and onMetaData callback<br />

handlers can be added dynamically. This is demonstrated in the following listing:<br />

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

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

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

vid.attachNetStream(ns);<br />

addChild(vid);<br />

The DynamicCustomNetStream class is as follows:<br />

package<br />

{<br />

import flash.net.NetConnection;<br />

import flash.net.NetStream;<br />

public dynamic class DynamicCustomNetStream ext<strong>en</strong>ds NetStream<br />

{<br />

private var nc:NetConnection;<br />

public function DynamicCustomNetStream()<br />

{<br />

nc = new NetConnection();<br />

nc.connect(null);<br />

super(nc);<br />

}<br />

}<br />

}<br />

Ev<strong>en</strong> with no handlers for the onMetaData and onCuePoint callback handlers, no errors are thrown since the<br />

DynamicCustomNetStream class is dynamic. If you want to define methods for the onMetaData and onCuePoint<br />

callback handlers, you could use the following code:<br />

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

ns.onMetaData = metaDataHandler;<br />

ns.onCuePoint = cuePointHandler;<br />

ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");<br />

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

vid.attachNetStream(ns);<br />

addChild(vid);<br />

function metaDataHandler(infoObject:Object):void<br />

{<br />

trace("metadata");<br />

}<br />

function cuePointHandler(infoObject:Object):void<br />

{<br />

trace("cue point");<br />

}<br />

Last updated 6/6/2012<br />

490

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

Saved successfully!

Ooh no, something went wrong!