Load File Flex 2

127 views Asked by At

How to load a file from a user selection?

In later flex versions is available the method FileReference.load(). But in flex 2 there isn't.

I want to do something like this:

var fileRef:FileReference= new FileReference();
button.addEventListener(MouseEvent.CLICK, onButtonClick);

function onButtonClick(e:MouseEvent):void {
    fileRef.browse([new FileFilter("Images", "*.jpg;*.gif;*.png")]);
    fileRef.addEventListener(Event.SELECT, onFileSelected);
}

function onFileSelected(e:Event):void {
    fileRef.addEventListener(Event.COMPLETE, onFileLoaded);
    fileRef.load();
}

function onFileLoaded(e:Event):void {
    var loader:Loader = new Loader();
    loader.loadBytes(e.target.data);
}
0

There are 0 answers