Playing back external FLV files dynamically

You can load FLV files at runtime to play in a SWF file. You can load them into a video object or into a component such as the FLVPlayback component. The following example shows how to play back a file named clouds.flv in a video object.

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

  1. Create a new Flash document called playFLV.fla.
  2. In the Library panel (Window > Library), select New Video from the Library
    pop-up menu.
  3. In the Video Properties dialog box, name the video symbol and select Video (ActionScript controlled).
  4. Click OK to create a video object.
  5. Drag the video object from the Library panel to the Stage to create a video object instance.
  6. With the video object selected on the Stage, type my_video in the Instance Name text box in the Property inspector (Window > Properties > Properties).
  7. Select Frame 1 in the Timeline, and open the Actions panel (Window > Actions).
  8. Type the following code in the Actions panel:
    this.createTextField("status_txt", 999, 0, 0, 100, 100);
    status_txt.autoSize = "left";
    status_txt.multiline = true;
    // Create a NetConnection object
    var my_nc:NetConnection = new NetConnection();
    // Create a local streaming connection
    my_nc.connect(null);
    // Create a NetStream object and define an onStatus() function
    var my_ns:NetStream = new NetStream(my_nc);
    my_ns.onStatus = function(infoObject:Object):Void {
        status_txt.text += "status (" + this.time + " seconds)\n";
        status_txt.text += "\t Level: " + infoObject.level + "\n";
        status_txt.text += "\t Code: " + infoObject.code + "\n\n";
    };
    // Attach the NetStream video feed to the Video object
    my_video.attachVideo(my_ns);
    // Set the buffer time
    my_ns.setBufferTime(5);
    // Begin playing the FLV file
    my_ns.play("http://www.helpexamples.com/flash/video/clouds.flv");
    
  9. Select Control > Test Movie to test the document.

For information on preloading FLV files, see "Preloading FLV files" on page 507. For information on dynamically loading FLV video into components, see Conponents Language Reference. For information on FLV files and the server, and FLV files and playing FLV files locally on the Macintosh, see Configuring your server for FLV files.


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