title: "Error #2038" : while file upload in flex
body: <p>I figured out an error as Error #2038 for IOEvent while file uploading in flex.</p>
  
  <p>I googled out but i didn't find any proper solution may be how to implement that. The code is working properly before. But now its showing this error.</p>
  
  <p>This is working in IE but in other browsers its showing error.</p>
  
  <p>Any body having idea ?</p>
  
  <p>Okay here is the AS3 code...please check it out</p>
  
  <pre><code>package com.firstplanet.views.actions
  {
  import com.adobe.serialization.json.JSON;
  import com.firstplanet.events.ErrorLogEvent;
  import com.firstplanet.events.SaveAdminItemEvent;
  import com.firstplanet.model.ModelLocator;
  import com.firstplanet.views.modules.admin.winProgress;
  
  import flash.display.DisplayObject;
  import flash.events.DataEvent;
  import flash.events.Event;
  import flash.events.IOErrorEvent;
  import flash.events.KeyboardEvent;
  import flash.events.ProgressEvent;
  import flash.events.SecurityErrorEvent;
  import flash.net.FileFilter;
  import flash.net.FileReference;
  import flash.net.FileReferenceList;
  import flash.net.Responder;
  import flash.net.URLRequest;
  import flash.net.URLRequestMethod;
  import flash.net.URLVariables;
  import flash.ui.Keyboard;
  
  import mx.controls.Alert;
  import mx.core.FlexGlobals;
  import mx.events.FlexEvent;
  import mx.managers.PopUpManager;
  
  public class FileUploader
  {
      public function FileUploader()
      {
      }
  
      [Bindable]private var theModel:ModelLocator = ModelLocator.getInstance(); 
      private var urlRequest:URLRequest;
      private var fileReference:FileReference;
      private var fileReferenceList:FileReferenceList;
      private var fileList:Array;
      private var isLargerFile:Boolean;
      private var _winProgress:winProgress;
      private var __errorEvt:ErrorLogEvent;
  
      [Bindable] public var photoName:String;
      [Bindable] public var theExtension:String;
      private var thePhotoTypeID:Number;
      [Bindable]public var file_name:String="";
      public var theAdminItem:Object = new Object();
      public var serverSideScript:String = "assets/php/FileUploader.php";
      private var max_file_size:Number;
      public var saveDet:Object;
      public var theAdminObj:Object;
      public var isUpload:Boolean;
  
  
      public function chooseFiles(fileType:String,fileFormat:String,max_size:Number):void
      {
          fileReferenceList = new FileReferenceList();
          fileReferenceList.addEventListener(Event.SELECT, onSelectFile);
          fileReferenceList.addEventListener(Event.CANCEL,onCancel);
          var arr:Array = [];
          arr.push(new FileFilter(fileType, fileFormat));
          fileReferenceList.browse(arr);
          max_file_size = max_size;
          if(fileType == "All")
          {
              isUpload = true;
          }
      }
      private function onCancel(event:Event):void{
          theModel.tempFlag = false;
      }
      private function convertBytestoMB(maxFileSize:Number):Number
      {
          var theMb:Number;
          theMb = maxFileSize/1024;
          theMb = theMb/1024;
  
          return theMb;
      }
      public function onSelectFile(event:Event):void
      {
          var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
          fileList = fileReferenceList.fileList;
  
          // get the first file that the user chose
          fileReference = FileReference(fileList[0]);
          file_name = fileList[0].name;
          //newFileLabel.label=fileList[0].name;
  
          //if(fileList[0].size &gt; maxFileSize)
          if(fileList[0].size &gt; Number(max_file_size))
          {
              //var theMB:Number = convertBytestoMB(maxFileSize);
              var theMB:Number = convertBytestoMB(max_file_size);
              theModel.uploadStatusMessage = "Selected file is around "+Math.round(convertBytestoMB(fileList[0].size))+" MB. Please select a file that must not exceed "+theMB+ " MB. ";
              theModel.saveErrorLogs("CertificateUpload",theModel.uploadStatusMessage);
              Alert.show(theModel.uploadStatusMessage);
              isLargerFile = true;
              return;             
          }
          else
          {
  
              theModel.uploadStatusMessage = "";
              isLargerFile = false;
              theModel.saveErrorLogs("CertificateUpload","This is not a large file");
              //saveBtn.enabled = true;
  
          }
  
          //previewfileName=fileList[0].name;
          if(isUpload)
          {
              if(theModel.fileManagerVO!=null)
              {
                  uploadFile("../../"+theModel.fileManagerVO.folderPath,null,null);
                  theModel.saveErrorLogs("CertificateUpload","Upload file path : ../../"+theModel.fileManagerVO.folderPath);
              }
          }
      }
  
      public function uploadFile(path:String,theAdminItem:Object,saveDetObj:Object):void 
      {
          saveDet = saveDetObj;
          theAdminObj = theAdminItem;
  
          if(fileList!=null)
          {
              if(isLargerFile)
              {
                  Alert.show(theModel.uploadStatusMessage);
                  return;
              }
              theModel.deleteOldFile = false;
              if(theAdminItem!=null)
              {
                  theModel.deleteOldFile = true;
                  if(theAdminItem.url!=null)
                  {
                      theModel.oldFileName = theAdminItem.url; 
                  }
              }
  
              _winProgress = winProgress(PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, winProgress, true));
              _winProgress.btnCancel.removeEventListener("click", onUploadCanceled);
              _winProgress.btnCancel.addEventListener("click", onUploadCanceled);
              //_winProgress.title = "Uploading file to " + domain;
  
              if(fileList!=null)
              {
                  _winProgress.txtFile.text = fileList[0].name;
                  file_name = fileList[0].name;
              }
              _winProgress.progBar.label = "0%";
              PopUpManager.centerPopUp(_winProgress);
  
              // Variables to send along with upload
              var sendVars:URLVariables = new URLVariables();
              sendVars.action = "upload";
              sendVars.path = path;
  
              var request:URLRequest = new URLRequest();
              request.data = sendVars;
              request.url = serverSideScript;
              request.method = URLRequestMethod.POST;
              fileReference = new FileReference();
              fileReference = FileReference(fileList[0]);
              fileReference.addEventListener(Event.OPEN, onUploadOpen);
              fileReference.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
              fileReference.addEventListener(Event.COMPLETE, onUploadComplete);
              fileReference.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError);
              fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadSecurityError);
              fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadCompleteReturn);
              fileReference.upload(request);
          }
          else
          {
              //saveItem();
              theModel.deleteOldFile = false;
              submitData(saveDet,theAdminObj);
  
          }
      }
      private function onUploadOpen(evt:Event):void
      {
          _winProgress.uploadProgressMessage.text = "Uploading please wait..."
      }
      // Get upload progress
      private function onUploadProgress(event:ProgressEvent):void 
      {
          var numPerc:Number = Math.round((Number(event.bytesLoaded) / Number(event.bytesTotal)) * 100);
          _winProgress.progBar.setProgress(numPerc, 100);
          _winProgress.progBar.label = numPerc + "%";
          _winProgress.progBar.validateNow();
          if (numPerc &gt; 90) 
          {
              _winProgress.btnCancel.enabled = false;
              //_winProgress.uploadProgressMessage.text = "Cropping your photo..Please wait..."
          } 
          else 
          {
              _winProgress.uploadProgressMessage.text = "Uploading please wait..."
              _winProgress.btnCancel.enabled = true;
          }
      }
      private function onUploadComplete(event:Event):void 
      {
          PopUpManager.removePopUp(_winProgress);
          _winProgress.uploadProgressMessage.text = "Please wait..."
          theModel.uploadStatusMessage="File have been uploaded.";
          theModel.saveErrorLogs("CertificateUpload",theModel.uploadStatusMessage);
          if(isUpload)
          {
              theModel.fileManagerVO.gatewayConnection.call( "data.files.getFiles", new Responder(theModel.fileManagerVO.onFileResult, theModel.fileManagerVO.onFault),theModel.fileManagerVO.folderPath);
          }
      }
      public function onUploadCompleteReturn(evt:DataEvent):void
      {
          if(evt!=null)
          {
              if(evt.data!=null)
              {
                  try
                  {
                      theModel.saveErrorLogs("CertificateUpload","came to onUploadCompleteReturn");
                      var rawData:String = evt.data as String;
                      var manager:Array  = JSON.decode(rawData);
                      if(manager!=null &amp;&amp; manager[0]!=null)
                      {
                          var tempObj:Object = manager[0] as Object;
                          var status:Boolean = tempObj.theStatus as Boolean;
                          if(status)
                          {
                              if(tempObj.FileName!=null)
                              {
                                  photoName = tempObj.FileName as String;
                              }
                              if(tempObj.theExtension!=null)
                              {
                                  theExtension = tempObj.theExtension as String;
                              }
                              theModel.uploadStatusMessage="File have been uploaded.";
                              theModel.isPhotoUploaded = true;
                              if(!isUpload)
                              {
                                  submitData(saveDet,theAdminObj);
                              }
                          }
                          else
                          {
                              photoName = "";
                              theModel.uploadStatusMessage="That file was not a recognised type or was unable to be decoded.";
                          } 
                      }
                      PopUpManager.removePopUp(_winProgress);
  
                  }
                  catch(e:Error)
                  {
                      Alert.show("Error in uploading the file");
                  }
              }
              else
              {
                  Alert.show("Error in uploading the file");
              }
          }
      }
      private function onUploadIoError(event:IOErrorEvent):void 
      {
          theModel.uploadStatusMessage="IO Error in uploading file.";
          PopUpManager.removePopUp(_winProgress);
          theModel.saveErrorLogs("CertificateUpload",event.text);
          //Alert.show("IO Error in uploading file.", "Error");
      }
      // Called on upload security error
      private function onUploadSecurityError(event:SecurityErrorEvent):void 
      {
          theModel.uploadStatusMessage="Security Error in uploading file.";
          theModel.saveErrorLogs("CertificateUpload",theModel.uploadStatusMessage);
          //Alert.show("Security Error in uploading file.", "Error");
          PopUpManager.removePopUp(_winProgress);
          _winProgress == null;
          fileReference.cancel();
      }
      // Called on upload cancel
      private function onUploadCanceled(event:Event):void 
      {
          PopUpManager.removePopUp(_winProgress);
          theModel.uploadStatusMessage = "You have cancelled the operation";
          _winProgress == null;
          fileReference.cancel();
          //clearUpload();
      }
  
      private function submitData(theObj:Object,theAdminItem:Object):void
      {
          if(photoName!=null)
          {
              theObj["url"] = photoName;
          }
          else
          {
              theObj["url"] = theAdminItem.url;
          }
          if(theExtension!=null)
          {
              theObj["type"] = theExtension;
          }
          else
          {
              theObj["type"] = theAdminItem.audio_type;
          }
  
          theModel.updateCourseDetails(theObj,'image');
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The error </p>
  
  <pre><code> [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038"]
  </code></pre>