Playing back external FLV files dynamically

As an alternative to importing video into the Flash authoring environment, you can use ActionScript to dynamically play back external FLV files in Flash Player. You can play back FLV files from an HTTP address or from the local file system. To play back FLV files, you use the NetConnection and NetStream classes and the attachVideo() method of the Video class. (For complete information, see NetConnection class, NetStream class, and Video.attachVideo().)

You can create FLV files by importing video into the Flash authoring tool and exporting it as an FLV file. (See Macromedia Flash Video (FLV).) If you have Flash Professional, you can use the FLV Export plug-in to export FLV files from supported video-editing applications. (See Exporting FLV files from video-editing applications (Flash Professional only).)

Using external FLV files provides certain capabilities that are not available when you use imported video:

The following procedure shows how you would play back a file named videoFile.flv that is stored in the same location as your SWF file.

To play back an external FLV file in a Flash document:

  1. With the document open in the Flash authoring tool, in the Library panel (Window > Library) select New Video from the Library options menu to create a video object.
  2. Drag a video object from the Library panel onto the Stage. This creates a video object instance.
  3. With the video object selected on the Stage, in the Property inspector (Window > Properties) enter my_video in the Instance Name text box.
  4. Open the Components panel (Window > Development Panels > Components) and drag a TextArea component to the Stage.
  5. With the TextArea object selected on the Stage, enter status in the Instance Name text box in the Property inspector.
  6. Select Frame 1 in the Timeline, and open the Actions panel (Window > Development Panels > Actions).
  7. Add the following code to the Actions panel:
    // Create a NetConnection object:
    var netConn:NetConnection = new NetConnection();
    // Create a local streaming connection:
    netConn.connect(null);
    // Create a NetStream object and define an onStatus() function:
    var netStream:NetStream = new NetStream(netConn);
    netStream.onStatus = function(infoObject) {
      status.text += "Status (NetStream)" + newline;
      status.text += "Level: "+infoObject.level + newline;
      status.text += "Code: "+infoObject.code + newline;
    };
    // Attach the NetStream video feed to the Video object:
    my_video.attachVideo(netStream);
    // Set the buffer time:
    netStream.setBufferTime(5);
    // Being playing the FLV file:
    netStream.play("videoFile.flv");