       loader.data.loadTime = new Date().getTime();
       loader.loadBytes(obj.data as ByteArray);
       obj = null;
+    }
+
+    private function onLoadComplete(event:Event):void {
+      if (!playing) { return; }
+
+      var arr:Array = getChildren();
+      var loader:MJPGImage = event.currentTarget.loader as MJPGImage;
+      var bitmap:Bitmap = event.currentTarget.content;
+      if (bitmap != null) {
+        bitmap.smoothing = true;
+      }
+      loader.data.loading = false;
+
+      scaleAndPosition(loader);
+
+      timestamps.push(new Date().getTime());
+      if (timestamps.length > FLOATING_AVG_LENGTH) { timestamps.shift(); }
+
+      if (arr[arr.length - 1].data.loadTime <= loader.data.loadTime) {
+        if (MAX_IMAGES > 2) {
+          removeChild(loader);
+          addChild(loader);
+        } else if (MAX_IMAGES == 2) {
+          this.swapChildren(arr[0], arr[1]);
+        }
+      }
+
+      arr = getChildren();
+      for (var i:uint = 0; i < arr.length - 1; i++) {
+        loader = arr[i] as MJPGImage;
+
+        if (loader.data.inQue == true || loader.data.loading) { continue; }
+
+        if (imgBuf.length == 0) {
+          loader.data.inQue = true;
+          idleQueue.push(loader);
+        } else {
+          loadImage(loader, imgBuf.shift());
+        }
+      }
+
+      if (firstImage) {
+        ExternalInterface.call(ipCam.getJsEventCallbackName(), "started");
+        firstImage = false;
+      }
+    }
+
+    private function onImageError(event:IOErrorEvent):void {
+      var loader:MJPGImage = event.currentTarget.loader as MJPGImage;
+      loader.data.loading = false;
+      if (imgBuf.length == 0) {
+        loader.data.inQue = true;
+        idleQueue.push(loader);
+      } else {
+        loadImage(loader, imgBuf.shift());
+      }
     }
 
     private function scaleAndPosition(loader:MJPGImage):void {

    }

    private function createLoaders():void {
      for (var i:uint = 0; i < maxImages; i++) {
        var loader:MJPGImage = new MJPGImage();
        loader.cacheAsBitmap = false;
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);

    }

    public function getChildren():Array {
      var children:Array = [];
      for (var i:uint = 0; i < this.numChildren; i++) {
       children.push(this.getChildAt(i));
      }
      return children;
    }

    public function load(image:ByteArray):void {
      if (imgBuf.length >= MAX_IMAGES + 3) { imgBuf.shift(); }
      imgBuf.push({ data: image });

      if (!playing) {
        playing = true;
        for each (var loader:MJPGImage in getChildren()) {
          loader.data.inQue = true;
          idleQueue.push(loader);
        }
      }

      if (idleQueue.length > 0) {
        loadImage(idleQueue.shift(), imgBuf.shift());
      }
    }

