hi i have created a movie clip that should play external flv files i have placed the flv files in thier own key frames and have buttons that gottoand play frame number but when i click on the buttons it only play the 1st video in the 1st frame but the other dont play what script can i use to play the other frames with flv files

hi i have created a movie clip that should play external flv files i have placed the flv files in thier own key frames and have buttons that gottoand play frame number but when i click on the buttons it only play the 1st video in the 1st frame but the other dont play what script can i use to play the other frames with flv files

One option would be to have your flash file load an XML playlist and assign each of the entries in the file to an instance of a button on the stage.

I've got code for an AS2 FLV player I started to put together for my band a while back (using flash 8 pro), but I never got round to finishing it off....It works, but there are a few other tweaks I wanted to make to it...I'll go into that in a bit!
This neat little FLV player was made during a 30 minute lunch-break at work and it hasn't been touched since...Maybe I will finish it one day, but feel free to take the code and do with it what you will!

At the present time, I've got a one frame, one layer movie with an instance of the FLV playback component (called m_player) and four buttons (btn0, btn1, btn2 and btn3) on the stage and that's about it!

This is what the XML file (vidPlaylist.xml) looks like:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<videolist>
	<video>
		<title>video1.flv</title>
		<description>This is the first video...</description>
	</video>
	<video>
		<title>video2.flv</title>
		<description>This is the second video...</description>
	</video>
	<video>
		<title>video3.flv</title>
		<description>This is the third video...</description>
	</video>
	<video>
		<title>video4.flv</title>
		<description>This is the fourth video...</description>
	</video>
</videolist>

Note: For this little project I've got the main swf, the playlist and the videos in the same directory, so the 'title' fields in the xml file are also the paths of the video files. (I eventually planned to use a separate 'path' field for the file path and the 'title' field for the button text!)

Anyway, below is the bit of actionscript used on frame 1 which loads the xml file, assigns each of the playlist items to a button.
Pressing a button will cause the selected movie to be loaded and played in the FLV component...By default, the first movie in the list will be loaded into the component, the user can start playback by pressing the play control on the playback component.
AS2 code below:

stop();
/*********************************************************************************************************/
// global objects....
// playlist object for the playlist from raw xml data
	var playlistData:Object = new Object();
	playlistData.list = new Array();
	
	var descriptions:Object = new Object();
	descriptions.list = new Array();
	
// Create a videos object to hold a video	
	var videos:Object = new Object();

// xml onload function
function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		trace("xmlNode = " + xmlNode);
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			playlistData.list[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
			descriptions.list[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
		}
		setupVideo();
	} else {
		content = "file not loaded!";
	}
}

function setupVideo():Void
{
	// Set up all video feeds in a single component
	videos.list = new Array();
	for(var loop=0; loop<playlistData.list.length; ++loop)
	{
		videos.list[loop] = playlistData.list[loop];
	}
	
	videos.loop = false;
	videos.length = 1;
	videos.loaded = false;
	
	// Path to FLVPlayback components
	var m = this.m_Player;
	
	// Set the path of the first video feed
	m.contentPath = videos.list[0];
	
	// Set a 'ready' event handler to load the videos
	videos.ready = function( evt:Object ):Void
	{
		if(!this.loaded){
			this.loaded = true;
			for( var n=1; n<this.list.length; n++ ){
				if( videos.list[n].indexOf(".flv") != -1 ){
					m.activeVideoPlayerIndex = n;
					m.contentPath = videos.list[n];
					this.length++;
				}
			}
			m.activeVideoPlayerIndex = 0;
		}
	}
	m.addEventListener("ready",videos);
	
	// Set a 'complete' event handler to load the next video
	videos.complete = function( evt:Object ):Void
	{
		var nextIndex = Number(evt.vp)+1;
		if( nextIndex == this.length){
			if( this.loop ){
				nextIndex = 0;
			}else{
				return;
			}
		}
		m.activeVideoPlayerIndex = nextIndex;
		m.visibleVideoPlayerIndex = nextIndex;
		m.play();
	}
	m.addEventListener("complete",videos);
	
	// End Set Videos Behavior		
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("vidPlaylist.xml");

The only other code is the short bit of code on the button instances:

on (click) {

	// Set Video Index Behavior
	var bWasPlaying:Boolean = this._parent.m_Player.playing;
	this._parent.m_Player.stop();
	this._parent.m_Player.activeVideoPlayerIndex = 0;
	this._parent.m_Player.visibleVideoPlayerIndex = 0;
	if(bWasPlaying)
		this._parent.m_Player.play();
	
	// End Set Video Index Behavior			
}

Note: all of the above code is the same for all of the buttons
except the lines :

this._parent.m_Player.activeVideoPlayerIndex = 0;
	this._parent.m_Player.visibleVideoPlayerIndex = 0;

The values of these variables are hard coded for each button, (0 for btn0, 1 for btn1 etc). So as you can see the above code is from btn0!

I planned to eventually make that bit of code more dynamic by using substr on the buttons instance name to deduce the number at the end of the instance name
i.e. off the top of my head, something like:

var instanceIdx:Number = Number(this._name.substr(-1,1));
this._parent.m_Player.activeVideoPlayerIndex = instanceIdx;
this._parent.m_Player.visibleVideoPlayerIndex = instanceIdx;

Then the AS on each of the buttons would be the same..no need for hard coded values!
This method would allow for a maximum of 10 buttons/movies to be in the xml file!
(i.e. buttons with instance names btn0..btn9)

What I've got left to do (if I ever get around to finishing it) is alter the movie so that buttons (and related AS code) are added dynamically, depending on the number of files listed in the xml file. Also creating a text area to put a description of the currently loaded vid and populating the button labels with the title of the corresonding vid are some of the other improvements I planned to make.

As mentioned, the AS2 code works....
Pressing one of the four buttons will load the corresponding video into the component...pressing a button when another video is already playing will cause the selected video to load and play.
Pressing a button when another video is stopped will cause the new video to be loaded, but it won't play until the user hits the play button!

But having said that it is AS2...Somewhat undesirable, but if necessary porting it to AS3 shouldn't be too difficult... I believe that the xml loading code may be the main thing to need altering, but the basic structure and principles used in the rest of the code will remain more or less the same!

Hope this is of some help,
Jas.

P.s. I just zipped up the files with a hastily put together readme.
In the zip there's a folder with a Flash 8 Pro/AS2 source .fla, a precompiled .swf, a skin for the FLV component, the XML playlist and the aforementioned README.

After unzipping the folder, all you need to do is copy four FLV videos into the directory and edit the 'title' fields of the XML file to include the filenames of the FLV's and then run the .swf to view the vids!

Note: The .fla was created using Flash 8 Pro, so the precompiled .swf will probably only work with FLV's encoded using the flash 8 video encoder or earlier...Videos encoded using later versions of the video encoder may not work properly!

loading the .fla into CS3 or CS4 and re-exporting the .swf may or may not work....I've no idea as I don't own CS3/CS4...I use Flashdevelop for my AS3 stuff!!

Anyways, enough o' my inane wibbling... The .zip file is attached!

J.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.