Problems with FLVs in AS3

We’ve created our own media player that will handle FLVs, SWF and MP3 files. Its in the library as a linked item and we wrote a class to handle everything for it. First we started coding for the FLVs (not getting to the other 2 yet) and we’re having problems with them. Sometimes the FLV won’t load at all, sometimes it will stop about 2 to 3 seconds into the FLV and won’t play anymore, and 100% of the time, if we go to a new frame (this is for CBT) and load another FLV it won’t show up at all. While IN flash, it will load the first FLV, but when running it as a SWF or Published EXE, its “sketchy” about loading even the first FLV.
the information is pulled from an XML file that has what file it is, the position on the screen, etc. The FLV lives in the same directory as the SWF file does as well.
To load in the mediaPlayer and FLV file we use this:

content_mc.addChild(new mediaPlayer(mediaFile, myType, mediaX, mediaY));

the content_mc is an empty movie clip that just sits on the stage so we can go through and erase all the children for the next frame:

var mcNumChildren:uint = content_mc.numChildren;
 for(var c:uint=0; c<mcNumChildren; c++) {  
  content_mc.removeChildAt(0);
 }

Heres the class for the mediaPlayer linked library item.


package { 
 import flash.display.Sprite;
 import flash.display.MovieClip;
 import flash.display.SimpleButton;
 import flash.events.SecurityErrorEvent;
 import flash.net.NetConnection;
 import flash.net.NetStream;
 import flash.net.URLLoader;
 import flash.net.URLRequest;
 
 import flash.media.Video;
 import flash.media.SoundTransform;
 
 /*
 import flash.events.Event;
 import flash.events.MouseEvent;
 import flash.events.TimerEvent;
 import flash.events.NetStatusEvent;
 import flash.events.SecurityErrorEvent;
 */
 
 import flash.events.*;
 
 import flash.utils.Timer;  
 
 public class mediaPlayer extends Sprite {
  private var _video:Video;
  private var _stream:NetStream;
  private var _duration:uint;
  private var _progress:Timer;
  private var _mediaFile:String;
  private var _mediaType:String;
  private var _mediaX:Number;
  private var _mediaY:Number;
  private var _currentPos:uint;
  private var _seekTimer:Timer;
  private var _seekDirection:Number;
  private var _doProgDrag:Boolean;
  private var _doVolumeDrag:Boolean;
  private var _volume:Number;
  private var _volumeTransform:SoundTransform;
  private var _isMuted:Boolean;
  private var _mediaLoader:URLLoader;
 
  public function playFLV() {
   _video = new Video();   
   var connection:NetConnection = new NetConnection();
   connection.connect(null);
   _stream = new NetStream(connection);
   _stream.play(_mediaFile);
 
   var Client:Object = new Object();
   Client.onMetaData = onMetaData;
   _stream.client = Client;
   _video.attachNetStream(_stream);
   _video.y = -(_video.height);
 
   _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
   _stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, getAsyncError);
   this.y = _mediaY + _video.height;
   this.mediaContainer_mc.addChild(_video);
  }
  public function mediaPlayer(mediaPath:String, mediaType:String, mediaX:Number, mediaY:Number) {
   _duration = 0;
   _mediaFile = mediaPath;
   _mediaX = mediaX;
   _mediaY = mediaY;
   _mediaType = mediaType;
   _currentPos = 0;
   _doProgDrag = false;
   _doVolumeDrag = false;
   _volumeTransform = new SoundTransform();
   _volume = _volumeTransform.volume * 100;
   _isMuted = false;
 
   if(_volume < 0) _volume = 0;
   if(_volume > 100) _volume = 100;
 
   _progress = new Timer(1);
   _progress.addEventListener(TimerEvent.TIMER, onTimer);
   _progress.start();
 
   _seekTimer = new Timer(500);
   _seekTimer.addEventListener(TimerEvent.TIMER, onSeek);
 
   this.x = _mediaX;
   this.addEventListener(Event.REMOVED_FROM_STAGE, closeVideo);
 
   this.progressBar_mc.stop();
   this.progress_mc.buttonMode = true;
   this.progress_mc.useHandCursor = true;
   this.progress_mc.addEventListener(MouseEvent.MOUSE_DOWN, sliderStart);
   this.progress_mc.addEventListener(MouseEvent.MOUSE_UP, sliderStop);
   this.progress_mc.addEventListener(Event.ENTER_FRAME, progressSlide);
 
   this.volumeBar_mc.stop();
   this.volumeBar_mc.gotoAndStop(_volume);   
   this.volume_mc.x = (_volume * 79) / 100;
   this.volume_mc.buttonMode = true;
   this.volume_mc.useHandCursor = true;
   this.volume_mc.addEventListener(MouseEvent.MOUSE_DOWN, sliderStart);
   this.volume_mc.addEventListener(MouseEvent.MOUSE_UP, sliderStop);
   this.volume_mc.addEventListener(Event.ENTER_FRAME, volumeSlide);
 
   this.mute_mc.gotoAndStop("off");
   this.mute_mc.buttonMode = true;
   this.mute_mc.useHandCursor = true;
   this.mute_mc.addEventListener(MouseEvent.MOUSE_OVER, muteOver);
   this.mute_mc.addEventListener(MouseEvent.MOUSE_DOWN, muteDown);
   this.mute_mc.addEventListener(MouseEvent.CLICK, muteClick);
   this.mute_mc.addEventListener(MouseEvent.MOUSE_OUT, muteOut);
 
   this.pause_btn.enabled = true;
   this.pause_btn.visible = true;
   this.pause_btn.addEventListener(MouseEvent.CLICK, playPause);
 
   this.play_btn.enabled = false;
   this.play_btn.visible = false;
   this.play_btn.addEventListener(MouseEvent.CLICK, playPause);
 
   this.stop_btn.addEventListener(MouseEvent.CLICK, stopVideo);
 
   this.rewind_btn.addEventListener(MouseEvent.MOUSE_DOWN, rewindVideo);
   this.rewind_btn.addEventListener(MouseEvent.MOUSE_UP, stopSeek);
   this.fastForward_btn.addEventListener(MouseEvent.MOUSE_DOWN, forwardVideo);
   this.fastForward_btn.addEventListener(MouseEvent.MOUSE_UP, stopSeek);
 
   if(_mediaType == "Video") {
    playFLV();
   } else if(_mediaType == "Flash") {
 
   } else if(_mediaType == "Sound") {
 
   }
  }
 
  private function onMetaData(data:Object):void {
   _duration = data.duration;
   _video.width = _video.videoWidth;
   _video.height = _video.videoHeight;
   trace(data.duration);
  }
 
  private function onNetStatus(event:NetStatusEvent):void {
   trace(event.info.code);
 
   if(event.info.code == "NetStream.Play.Stop") {
    this.pause_btn.enabled = false;
    this.pause_btn.visible = false;
    this.play_btn.enabled = true;
    this.play_btn.visible = true;
   }
  }
 
  private function getAsyncError(event:SecurityErrorEvent):void {
   trace("Security Error: " + event)
  }
 
  private function onTimer(event:TimerEvent):void {
   if(_duration > 0 && _stream.time > 0) {
    _currentPos = Math.round(((_stream.time) * 100) / Math.round(_duration))+1;
    if(_currentPos > 100) _currentPos = 100;
    this.progressBar_mc.gotoAndStop(_currentPos);    
    var progX:uint = (_currentPos * 3);
    this.progress_mc.x = progX;
   }
  }
 
  private function onSeek(event:TimerEvent):void {   
   if(_duration > 0 && _stream.time > 0) {
    var myTime:uint = _stream.time + _seekDirection;
    _stream.seek(myTime);
   }
  }
 
  private function stopSeek(event:Event):void {
   _seekTimer.stop();
  }
 
  private function closeVideo(event:Event):void {
   _stream.close();
  }
 
  private function playPause(event:MouseEvent):void {
   if(event.currentTarget == pause_btn) {
    _stream.pause();
    this.pause_btn.enabled = false;
    this.pause_btn.visible = false;
    this.play_btn.enabled = true;
    this.play_btn.visible = true;
   } else {
    if(int(_duration) == int(_stream.time)) {
     _stream.seek(0);     
    }
    _stream.resume();
    this.pause_btn.enabled = true;
    this.pause_btn.visible = true;
    this.play_btn.enabled = false;
    this.play_btn.visible = false;
   }
  }
 
  private function stopVideo(event:MouseEvent):void {
   _stream.pause();
   _stream.seek(0);
   this.pause_btn.enabled = false;
   this.pause_btn.visible = false;
   this.play_btn.enabled = true;
   this.play_btn.visible = true;
  }
 
  private function rewindVideo(event:MouseEvent):void {
   _seekDirection = -5;
   _seekTimer.start();
  }
 
  private function forwardVideo(event:MouseEvent):void {
   _seekDirection = 5;
   _seekTimer.start();
  }
  private function progressSlide(event:Event):void {
   if(_doProgDrag) {
    this.progress_mc.y = 2;
    if(this.progress_mc.x < 0) {
     this.progress_mc.x = 0;
    }
    if(this.progress_mc.x > 300) {
     this.progress_mc.x = 300;
    }
 
    var mySlider:uint = Math.round(((this.progress_mc.x) / _duration) * 150);
    _stream.seek(mySlider);
 
    _currentPos = Math.round(((mySlider) * 100) / Math.round(_duration))+1;
    if(_currentPos > 100) _currentPos = 100;
    this.progressBar_mc.gotoAndStop(_currentPos);
   }
  }
 
  private function volumeSlide(event:Event):void {
   if(_doVolumeDrag) {
    this.volume_mc.y = 30;
    if(this.volume_mc.x < 0) this.volume_mc.x = 0;
    if(this.volume_mc.x > 79) this.volume_mc.x = 79;
    _volume = Math.round((this.volume_mc.x * 100) / 79);
    this.volumeBar_mc.gotoAndStop(_volume);
    if(!_isMuted) {
     _volumeTransform.volume = _volume / 100;
     _stream.soundTransform = _volumeTransform;
    }
   }
  }
 
  private function sliderStart(event:Event):void {
   if(event.currentTarget == progress_mc) {
    _progress.stop();   
    _stream.pause();
    _doProgDrag = true;
    this.progress_mc.startDrag();
   } else {
    _doVolumeDrag = true;
    this.volume_mc.startDrag();
   }
 
   stage.addEventListener(MouseEvent.MOUSE_UP, sliderStop);
  }
 
  private function sliderStop(event:Event):void {
   if(event.currentTarget == progress_mc) {
    this.progress_mc.stopDrag();
    _doProgDrag = false;
    _progress.start();   
    _stream.resume();  
   } else {
    this.volume_mc.stopDrag();
    _doVolumeDrag = false;
   }
 
   stage.removeEventListener(MouseEvent.MOUSE_UP, sliderStop);
  }
 
  private function muteOver(event:Event):void {
   this.mute_mc.gotoAndStop("over");
  }
 
  private function muteDown(event:Event):void {
   this.mute_mc.gotoAndStop("down");
  }
 
  private function muteOut(event:Event):void {
   if(_isMuted) {
    this.mute_mc.gotoAndStop("on");
   } else {
    this.mute_mc.gotoAndStop("off");
   }
  }
 
  private function muteClick(event:Event):void {
   if(_isMuted) {
    _volumeTransform.volume = _volume / 100;
    _stream.soundTransform = _volumeTransform;
   } else {
    _volumeTransform.volume = 0;
    _stream.soundTransform = _volumeTransform;
   }
   _isMuted = !_isMuted;
  }
 } 
}

does anyone know why this is giving me problems? we’ve had everyone here look at it, and we just can’t figure it out!