Loading video files

Loading videos using the NetStream and NetConnection classes is a multistep process:

  1. The first step is to create a NetConnection object. The NetConnection class lets you play streaming FLV files from either an HTTP address or a local drive by passing the value null to the connect() method, if you are connecting to a local FLV file that is not using a server such as Adobe's Flash Media Server 2 or Adobe Flex.
    var nc:NetConnection = new NetConnection();
    nc.connect(null);
    
  2. The second step is to create a NetStream object which takes a NetConnection object as a parameter and specify which FLV file you want to load. The following snippet connects a NetStream object to the specified NetConnection instance and loads an FLV named video.flv in the same directory as the SWF file:
    var ns:NetStream = new NetStream(nc);
    ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
    ns.play("video.flv");
    function asyncErrorHandler(event:AsyncErrorEvent):void
    {
        // ignore error
    }
    
  3. The third step is to create a new Video object and attach the previously created NetStream object using the Video class's attachNetStream() method. Then you can add the video object to the display list using the addChild() method, as seen in the following snippet:
    var vid:Video = new Video();
    vid.attachNetStream(ns);
    addChild(vid);
    

After entering the previous code, Flash Player will attempt to load the video.flv video file in the same directory as your SWF file.

TIP

 

To load FLV files from a web server, you might need to register the file extension and MIME type with your web server; check your web server documentation. The MIME type for FLV files is video/x-flv. For more information, see About configuring FLV files for hosting on a server.


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/00000255.html