views:

1816

answers:

4

I am trying to use the load method of FileReference object to load the data and use it to display a thumbnail of the selected image.

However, after calling fr.load(), fr.data remains null.

I'm using Flex Builder 3.0.2 on Windows 7 with Flex SDK 3.4 and Flash Player 10 Debug. If I evaluate fr.load() in Eclipse's watch variables list, I get an error reading "No such variable: load."

Anyone know why this is happening?

A: 

Did you pass anything to the fileReference.

e.g from a datagrid

var listFiles:DataGrid = new DataGrid();
var _refUploadFile:FileReference = new FileReference();        
_refUploadFile = listFiles.selectedItem.file;   

_refUploadFile.load();
Treby
+2  A: 

Are you waiting for the load() to complete? Try adding an EventListener to listen for the load to be finished.

FileReference docs

fr.addEventListener(Event.COMPLETE, function(e:Event):void {
                                        handleLoad(e);
                                    });

The handleLoad function that you write can then get at the data via e.target.data

dustmachine
This was the problem, thanks. I'd known earlier that I should wait for the event, but forgotten. Thanks again.
cookiecaper
+1  A: 

EDIT: This is applicable only to FP9.


Are you sure you are using the right class? FileReference does not have a load method or a data property. I guess you are referring to the URLLoader class - it does have both and that's what you should be using to load data. FileReference class is for downloading files from the server to the user's machine (not to the SWF) and uploading files from user's machine to the server.

Use URLLoader class for loading data to the SWF and Loader class to load other SWFs and images to your SWF. Loader class has a content property analogous to the data property of URLLoader that will hold the loaded content. The load() methods of both these classes are asynchronous (returns without waiting for the load to be completed) and hence, as @dustmachine noted, you can access the loaded data/content only after the Event.COMPLETE is fired.

var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onLoad);
urlLoader.load(new URLRequest(theURL));

private function onLoad(e:Event):void
{
  var urlLoader:URLLoader = URLLoader(e.target);
  trace(urlLoader.data);
}
Amarghosh
Thanks for this answer, but with ActionScript 3 and Flash Player 10, FileReference does have a load() method (which loads the content of the file into a ByteArray) and a data property (which contains the aforementioned ByteArray). I had to upgrade and reconfigure Flex Builder to get it to see these things, though.
cookiecaper
Thanks for correcting me - haven't done FP 10 specific stuff yet.
Amarghosh
A: 

I had the same problem with FileReference class and load() function. The problem can solved in this way:

  1. Open the "Flex Build Path" tab.
  2. Expand "Flex 3", select "playerglobal.swc" and click "Remove".
  3. Note the directory path in "Flex 3 - " (on my system it's /Applications/Adobe Flex Builder 3 Plug-in/sdks/3.2.0).
  4. Click "Add SWC" and navigate to the that path, and then deeper into frameworks/libs/player/10, select playerglobal.swc.
  5. Expand "playerglobal.swc", double-click "Link Type" and change it to "External".
  6. Open the "Flex Compiler" tab
  7. In "HTML wrapper", change the "Require Flash Player version" to 10.0.0.
Eugene