7 Replies Latest reply on Sep 3, 2010 7:52 AM by ranjit.sail

    Why would a FileReference.data property be null?

    cog_jonathan

      So I select a file using:

       

      file.browse()

       

      but after the file is selected,and file.load() is called, file.data still contains null. I checked the behavior of file.data and when it returns null - and none of these possibites seem to make much sense to me. Could it be some kind of security/sandboxing issue?

        • 1. Re: Why would a FileReference.data property be null?
          Gregory Lafrance Level 6

          Is the file read-only?

          1 person found this helpful
          • 2. Re: Why would a FileReference.data property be null?
            Barna Biro Level 3

            Hi Jonathan,

             

            The property "data" is null until you don't call load(); on the FileRerefence. Check Adobe LiveDocs for more information: http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html

             

            With best regards,

            Barna Biro

            • 3. Re: Why would a FileReference.data property be null?
              cog_jonathan Level 1

              I am calling file.load() before accessing file.data and it still returns null. And I have permissions on the file and also it is not read only.

              • 4. Re: Why would a FileReference.data property be null?
                ATIF FAROOQ

                hi,

                are you accessing data in fileReference complete Event ?

                1 person found this helpful
                • 5. Re: Why would a FileReference.data property be null?
                  Barna Biro Level 3

                  Hi again,

                   

                  Here's a really fast and working example:

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application 
                      xmlns:mx        ="http://www.adobe.com/2006/mxml" 
                      layout          ="absolute">
                      
                      <mx:Script>
                          <![CDATA[
                              import mx.controls.Alert;
                              
                              private var _fileRef:FileReference;
                              
                              private function onReadFile(event:MouseEvent):void
                              {
                                  _fileRef = new FileReference;
                                  _fileRef.addEventListener(Event.COMPLETE, onLoadComplete);
                                  _fileRef.addEventListener(Event.SELECT, onFileSelect);
                                  _fileRef.browse();
                              }
                              
                              private function onFileSelect(event:Event):void
                              {
                                  _fileRef.load();
                              }
                              
                              private function onLoadComplete(event:Event):void
                              {
                                  _fileRef.removeEventListener(Event.COMPLETE, onLoadComplete);
                                  _fileRef.removeEventListener(Event.SELECT, onFileSelect);
                                  
                                  Alert.show(_fileRef.data.readUTFBytes(_fileRef.data.length).toString());
                              }
                              
                          ]]>
                      </mx:Script>
                      
                      <mx:VBox
                          width               ="100%"
                          height              ="100%"
                          horizontalAlign     ="center"
                          verticalAlign       ="middle">
                          
                          <mx:Button
                              label       ="Read File"
                              click       ="onReadFile(event)"/>
                          
                      </mx:VBox>
                      
                  </mx:Application>
                  

                   

                  In case you get an error that is saying that "could not file method load() on FileRerefence" then you are not exporting the content to Flash Player 10. Don't forget that FileReference.load(); is only available from Flash Player 10.

                   

                  With best regards,

                  Barna Biro

                  • 6. Re: Why would a FileReference.data property be null?
                    cog_jonathan Level 1

                    Thank you. My mistake was thinking file.load() was syncronous.

                    • 7. Re: Why would a FileReference.data property be null?
                      ranjit.sail Level 1

                      Hi,

                       

                       

                      Starnge..but works. My filerefrence.data was null...

                       

                      but after removing playerglobal.swc from libs and adding again from

                       

                      \\Adobe Flash Builder 3 Plug-in\sdks\3.5.0\frameworks\libs\player\10

                       

                      it works .....

                       

                      My data is no more null..

                       

                       

                      Happy flexing

                       

                      Regards,

                      Ranjit