1 Reply Latest reply on Feb 8, 2010 10:57 AM by r0brh0des

    fileReferenceList[i]. load(); how to?

    r0brh0des

      So I am trying to retrieve the image ByteArray after select event fires for individual fileReferences within fileReferenceList and can't seem to get anywhere....no problem with single fileReference.


      If you call load() on individual postion in array nothing happens..no error but "data" property stays null.

       

      Saw a bug report post here but no resolution posted.. http://forums.adobe.com/message/2571341 ....however in the thread someone posted this:

      "FileReference.load() is an asynchronous function .. you need to make sure you keep a reference active so the garbage collector doesn't trash it."

       

      Can't figure out what poster meant by "keep reference active"......and on down list it mentions topic being posted as bug.

       

      Does anyone know what the deal is with this?

       

      Here's some code to demonstrate what I'm refering to:

       

      This works (fileReference sdk 3.5 and 4):

       

                  private function init():void{
                     
                      _file = new FileReference;
                     
                         _file.addEventListener(Event.SELECT, fileReference_select);
                         _file.addEventListener(Event.COMPLETE, fileReference_complete);
                     }

       

                  private function btn_click(evt:MouseEvent):void {
                      var arr:Array = [];
                      arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
                      _file.browse(arr);
                  }

       

                  private function fileReference_select(evt:Event):void {
                      _file.load();
                  }

       

                  private function fileReference_complete(evt:Event):void {
                      img.source = _file.data;
                      Alert.show(ObjectUtil.toString(_file));
                  }

       

      This doesn't (fileReferenceList  sdk 3.5 and 4):

       

                  private function init():void{

       

                      _fileRefList = new FileReferenceList;

       

                      _fileRef = new FileReference;

       

       

                        _fileRefList.addEventListener(Event.SELECT, fileReference_select);

       

                       _fileRefList.addEventListener(Event.COMPLETE, fileReference_complete);

       

                     }

       

                  private function btn_click(evt:MouseEvent):void {

       

                      var arr:Array = [];

       

                      arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));

       

                      _fileRefList.browse(arr);

       

                  }

       

                  private function fileReference_select(evt:Event):void {

       

                     

       

                          _fileRefList.fileList[0].load();

       

                          Alert.show(ObjectUtil.toString(_fileRefList.fileList[0]));

       

                  }

       

                  private function fileReference_complete(evt:Event):void {

       

                      img.source = _fileRefList.fileList[0].data;

       

                     

       

                  }

        • 1. Re: fileReferenceList[i]. load(); how to?
          r0brh0des Level 1

          Found this code elsewhere in forum that I think holds the key should anyone else who is stumped get here:

           

                      private function select(event:Event):void
                      
                      {
                      
                           for(var i:uint=0;i<reflist.fileList.length;i++)
                      
                              {
                      
                                reflist.fileList[i].addEventListener(Event.COMPLETE,open);
                      
                                reflist.fileList[i].load();
                      
                           }
                      
                      }
                      
                                         
                      
                      private function open(event:Event):void
                      
                      {
                      
                           var tempFileRef:FileReference = event.target as FileReference;
                      
                           loader = new Loader;
                      
                           loader.name = event.target.name;
                      
                           loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadArray);
                      
                           loader.loadBytes(tempFileRef.data);
                      
                      }
                      
                                         
                      
                      private function loadArray(event:Event):void
                      
                      {
                      
                                picArr.push({label:event.target.content.parent.name, data:event.target.content});
                      
                                listFiles.dataProvider = picArr;
                      
                      }