This content has been marked as final. Show 8 replies
Don't think there is access to local file system from Flex app however AIR apps can do this - see the File class
Once you read in the filestream you can convert it to XML Object and then handle it as you would any XML data source (e4x).
But that's a Bummer!
What if I put the XML file on my website, and loaded it from there?
Or included the XML file in the source code, like a DATA statement?
Or pre-parse the XML into an AS tree with something like perl, and include that in the source code as part of an AS script.
Yuck - I'd have to include the program with every data set.
I had hoped I could avoid a kludge.
BTW, livesource.adobe.com has been down all day. Fortunately the langref zip could still be downloaded.
I often put XML files onto the web server and then access from Flex code. Something like this:
protected function load_settings_data():void
data_URL = "./data_settings.xml";
data_request = new URLRequest(settings_data_URL);
data_loader = new URLLoader(settings_data_request);
} // try
Alert.show("load_settings_data - error message " + error.toString());
} // catch
} // load_settings_data
protected function settings_data_error(e:IOErrorEvent):void
Alert.show("ioError handled in settings_data_error: error " + e.text);
} // settings_data_error
protected function settings_data_loaded(event:Event):void
xml_to_use = XML(data_loader.data);
// do whatever you want with xml_to_use
} // settings_data_loaded
However, while you are developing on the local machine you will probably want to have some dummy data in a variable:
protected var data_internal:XML =
and swap this data in in the catch part of the first statement. Obviously the dummy data has to have the right structure but you can usually get away with just a few entries rather than the whole lot. Once you are happy, forget the local variable, put back the error handling and just use the file on your web server which can be updated whenever you want independently of the swf application.
Hope that helps,
Thank You Richard!
That's just the answer I needed! :-)
Also, check the Flex HTTPService. It can simply retrieve the xml data for you.
<mx:HTTPService id="myDataService" url="data/myData.xml" resultFormat="e4x"/>
Great! Looks even easier!
And that led me to check out E4X.
This whole program may be easier in Flex than I thought it would be!
"e4x" is just the current ActionScript implementation of XML(ecmascript for xml). Use it.
I also advise getting in the habit of using result handlers instead of directly binding to lastResult.
Here are some more snippets.
Wow! You guys are good!
Your "snippet" deserves a lot of study.