Class to Open object(s) from file with Flex in Air
by Nicolas Noben
Before, I wrote about How to save one or more objects to file using this class.
Today it’s time to read it and bring back the object in Flex.
The class
package com.idletogether
{
import flash.events.Event;
import flash.filesystem.*;
public class Opener
{
public static var file:File;
public static function openFile() :void
{
file = new File();
file.addEventListener(Event.SELECT, dirSelected);
file.browseForOpen('');
}
public static function dirSelected(e:Event) :void
{
// this will be our object back
var dat:Object = new Object();
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
dat = fileStream.readObject();
fileStream.close();
some.object = dat.data;
some.other.object = dat.structure;
}
}
}
How to use it
Simply…
import com.idletogether.Opener; Opener.openFile();
This example is very basic, but it is kept simple for the sake of being easy to understand. From there you can build up a much more tailored system. This should get you started.
Use the Expressions panel of Flex and add a ‘watch’ to the variable ‘dat’ to see what came back in and if it is in good form.
HTH,
Cheers.
Related Posts
- Class to Save object(s) to file with Flex in Air
- Flash / Flex / AIR Development Adelaide - Freelance Available...
- iminlikewithyou - A cool social flash environment
- 95.7% of Flash player 9 Penetration!
- McDonald's Polish site. Great Flash work and polished indeed.

Stay focussed
Del.icio.us
Reddit
Stumble it
Digg it


» Class to Save object(s) to file with Flex in Air Idle Together Says:
February 24th, 2009 at 1:58 pm[…] From here, find out how to get the object back into flex in the next post. […]