Technology blog oriented towards good design and impressive web applications.

IdleTogether Home

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





One Response


  1. » Class to Save object(s) to file with Flex in Air Idle Together Says:

    […] From here, find out how to get the object back into flex in the next post. […]

Leave a Comment







  Please note: Comments are reviewed before going public.