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 />

Navigation cue points create a keyframe at the specified cue point location, so you can use code to move a video player's<br />

playhead to that location. You can set particular points in a video file where you might want users to seek. For example,<br />

your video might have multiple chapters or segm<strong>en</strong>ts, and you can control the video by embedding navigation cue<br />

points in the video file.<br />

For more information on <strong>en</strong>coding Adobe video files with cue points, see “Embed cue points” in Using Flash.<br />

You can access cue point parameters by writing ActionScript. Cue point parameters are a part of the ev<strong>en</strong>t object<br />

received by the callback handler.<br />

To trigger certain actions in your code wh<strong>en</strong> an FLV file reaches a specific cue point, use the NetStream.onCuePoint<br />

ev<strong>en</strong>t handler.<br />

To synchronize an action for a cue point in an F4V video file, you must retrieve the cue point data from either the<br />

onMetaData() or the onXMPData() callback functions and trigger the cue point using the Timer class in ActionScript<br />

3.0. For more information on F4V cue points, see “Using onXMPData()” on page 497.<br />

For more information on handling cue points and metadata, see “Writing callback methods for metadata and cue<br />

points” on page 486.<br />

Writing callback methods for metadata and cue points<br />

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

You can trigger actions in your application wh<strong>en</strong> specific metadata is received by the player or wh<strong>en</strong> specific cue points<br />

are reached. Wh<strong>en</strong> these ev<strong>en</strong>ts occur, you must use specific callback methods as ev<strong>en</strong>t handlers. The NetStream class<br />

specifies the following metadata ev<strong>en</strong>ts that can occur during playback: onCuePoint (FLV files only), onImageData,<br />

onMetaData, onPlayStatus, onTextData, and onXMPData.<br />

You must write callback methods for these handlers, or the Flash runtime may throw errors. For example, the<br />

following code plays an FLV file named video.flv in the same folder where the SWF file resides:<br />

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

nc.connect(null);<br />

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

ns.addEv<strong>en</strong>tList<strong>en</strong>er(AsyncErrorEv<strong>en</strong>t.ASYNC_ERROR, asyncErrorHandler);<br />

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

function asyncErrorHandler(ev<strong>en</strong>t:AsyncErrorEv<strong>en</strong>t):void<br />

{<br />

trace(ev<strong>en</strong>t.text);<br />

}<br />

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

vid.attachNetStream(ns);<br />

addChild(vid);<br />

The previous code loads a local video file named video.flv and list<strong>en</strong>s for the asyncError<br />

(AsyncErrorEv<strong>en</strong>t.ASYNC_ERROR) to be dispatched. This ev<strong>en</strong>t is dispatched wh<strong>en</strong> an exception is thrown from<br />

native asynchronous code. In this case, it is dispatched wh<strong>en</strong> the video file contains metadata or cue point information,<br />

and the appropriate list<strong>en</strong>ers have not be<strong>en</strong> defined. The previous code handles the asyncError ev<strong>en</strong>t and ignores the<br />

error if you are not interested in the video file’s metadata or cue point information. If you had an FLV with metadata<br />

and several cue points, the trace() function would display the following error messages:<br />

Last updated 6/6/2012<br />

486

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

Saved successfully!

Ooh no, something went wrong!