Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Working with video > Writing callback methods for onCuePoint and onMetaData | |||
You can trigger actions in your application when specific cue points are reached or specific metadata is received by the player. To trigger such actions, you use the onCuePoint and onMetaData event handlers. You must write callback methods for these handlers, or Flash Player may throw errors. For example, the following code plays an FLV file named video.flv in the same folder as your SWF document:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.play("video.flv");
function asyncErrorHandler(event:AsyncErrorEvent):void
{
trace(event.text);
}
var vid:Video = new Video();
vid.attachNetStream(ns);
addChild(vid);
The previous code loads a local FLV file named video.flv and listens for the asyncError (AsyncErrorEvent.ASYNC_ERROR) to be dispatched. This event is dispatched when an exception is thrown from native asynchronous code. In this case, it is dispatched when an FLV contains metadata or cue point information, and the appropriate listeners have not been defined. The previous code handles the asyncError event and ignores the error if you are not interested in the video file's metadata or cue point information. If you had an FLV with metadata and several cue points, the following information would be traced:
Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.
The error occurs because the NetStream object was unable to find an onMetaData or onCuePoint callback method. There are several ways to define these callback methods within your applications:
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000260.html