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 Creating an application with the FLVPlayback component. For information on FLV files and the server, and FLV files and playing FLV files locally on the Macintosh, see About configuring FLV files for hosting on a server.

——————————————–

The statement that null must be passed to the connect method is confusing because it’s not always true. When connecting to the Flash Media Server to stream an FLV you DO WANT to pass a URI, for example:

var nc:NetConnection = new NetConnection();
nc.connect(“rtmp://myflashmediaserver.com/myapp”);

———————————————

source:

http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001571.html#189454

3 thoughts on “Playing back external FLV files dynamically

  1. Thanks for the info, however I get the following errors:

    1046: Type was not found or was not a compile-time constant: Void.

    Warning: 1060: Migration issue: The method createTextField is no longer supported. Use var tf= new TextField(); addChild(mc). For more information, see the DisplayObjectContainer class..

    Warning: 1090: Migration issue: The onStatus event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( ‘status’, callback_handler).

    and 4 others… this is in CS4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s