back to home
back to home
back to home  
TECHNOLOGY SUPPORT: HOW TO LOAD EXTERNAL VIDEO INTO FLASH    
 
 
    Using the NetStream and NetConnection classes
 

The NetConnection class lets you play streaming FLV files from either an HTTP address or a local drive. The NetStream object takes a NetConnection object as a parameter to specify which FLV file you want to load. The FLV file will inherit the position, rotation, and scale properties of the targeted video object it replaces. The upper left corner of the loaded image or FLV file aligns with the registration point of the targeted video object.

The NetStream class has a play variable that is assigned the FLV to be played.

ns.play(url);

  • url: String - This should contain the URL (absolute or relative) to the FLV file to be loaded into the video object. If WDIG will be passing the URL as a variable, please use _level0.moviePath

Example of assigning the ns.play value with a hard-coded FLV url:

ns.play("http://www.server.com/video.flv");

Example of assigning the ns.play value with a variable url value (to be set by WDIG):

my_ns.play(_level0.moviePath);

    A Working Example of the NetStream and NetConnection classes
 

The following example expects a variable, _level0.moviePath, to be set externally when the SWF file is published to the page.

When the user clicks the play button the ad will replace the my_video object with the FLV file defined by the _level0.moviePath, in this case clouds.flv.

Click on the play button to view the example. The code is briefly explained below. Click here for a zip file containing the original files for reference.

The actionscript code associated to the play button in the main SWF file:

   on (release)
   {
	my_ns.play("_level0.moviePath");
   }

Initializing the _level0.moviePath variable upon page render:

   SOB.flashFile = "sample_flv_player.swf?moviePath=clouds.flv";

    References
 

Adobe LiveDocs AS2 - The official documentation on the Adobe Flash NetStream and NetConnection classes for AS2.

Adobe LiveDocs AS3 - The official documentation on the Adobe Flash NetStream and NetConnection classes for AS3.

Zip File (10k) - A file containing the original Adobe Flash FLA file used for the example above.