Flash Video - Loading Files Twice, Don't Know Why

Hello All,

I’m writing a Flash video player that allows the user to select and play any of 3 different videos. If it’s the first time they’re playing any video, the program rolls an advertisement before going on to play the video they want.

The advertisement plays fine, but when it comes time to roll the user-selected movie the problems occur. The program tries to execute nsVideos.play(theMovie) twice in a row. Then it will lock up for a bit, play the movie for 2-3 seconds, and execute nsVideos.play(theMovie) again. It’s in some kind of infinite loop and it keeps repeating until the program finally crashes.

Each of the 3 buttons look like this:


btnMovies.onRelease = function():Void {
	playMovie("mymovie.flv");
};

function playMovie(theMovie:Object):Void {
	// First time playing movie so user has to watch an ad first.
	if (isFirstMovie) {
		nsVideos.onMetaData = function(vidDuration:Object) {
			trace(vidDuration.duration);
		};
		nsVideos.setBufferTime(vidDuration);
		nsVideos.play("advertisement.flv");
		isFirstMovie = false;
		nsVideos.onStatus = function(vidInfo:Object) {
			if (vidInfo.code == "NetStream.Play.Stop") {
				stopped = true;
			}
			if (vidInfo.code == "NetStream.Buffer.Empty") {
				if (stopped) {
					nsVideos.onMetaData = function(vidDuration:Object) {
						trace(vidDuration.duration);
					};
					nsVideos.setBufferTime(vidDuration);
					nsVideos.play(theMovie);
				};
			};
		};
	}
	else {
		nsVideos.onMetaData = function(vidDuration:Object) {
                trace(vidDuration.duration);
		};
		nsVideos.setBufferTime(vidDuration);
		nsVideos.play(theMovie);
	};
};

Thanks in advance to those who can help me out!