03-15-2011 02:04 PM
Okay, so I need to have about 200 Paragraphs of information stored in my app for use at any given time, and I'm wondering what would be smarter?
Store the paragraphs in SQLite? Or Hard-code the paragraphs into variables in the app?
This information will NOT be used in equations, and will be used 1 at a time.
Solved! Go to Solution.
03-15-2011 02:11 PM
When you say "1 at a time", do you mean accessed once, use once, then discarded? If that is the case, then a database or flat file might work. If you are going to load them all, then an XML file might be good. Keeping that amount of state, hard coded in the application can be difficult to maintain. If you are going to offer multiple languages, then a DB or flat files might be good too.
If they are all read-only, then an install in the app folder would work fine.
03-15-2011 02:19 PM
Certainly not SQLite, if the app won't change them.
I'd probably [Embed()] them to avoid even having to do File stuff.
Store in one file with unique separator string, and do a String.split() to convert the whole thing to an Array at run time.
[Embed('paragraphs.txt', mimeType='application/octet-stream')] public static const ParagraphData:Class; ... // use a more sophisticated separator here: var paragraphs:Array = new ParagraphData().toString().split('--separator--');
03-15-2011 02:28 PM
03-15-2011 02:36 PM
With a more complex structure, I'd strongly consider storing and parsing the data as XML instead, but it's not hard to do that with a string either. Just do an outer loop over the first split(), and on each chunk do another split() with a second separator to get the individual items within each "chunk".
I'd say anything beyond a single level of nesting would definitely warrant XML or something else like that. (I'd look at JSON too at that point.)
03-15-2011 04:20 PM
XML is probably the best solution. Easier to work with, I'm not a fan of JSON, that's why I've developed my own API with my web services and blog software.
And besides, there's a good amount of resources for working with XML!
03-15-2011 04:24 PM - edited 03-15-2011 04:25 PM
I would pretty much suggest going with XML. I have not idea what you are trying to achieve, but XML would allow you to set attributes or subnodes that would allow you to be much more specific with your data.
An example would be a language file for your application:
var my_xml:XML = new XML( <xml> <description> <english>Simple description using english</english> <other_language>Simple description using other language</other_language> </description> <title> <english>The title of the paragraph in english</english> <other_language>The title of the paragraph in other language</other_language> </title> </xml> ); var my_language:String = 'english'; trace( my_xml.description[ my_language ] ); trace( my_xml.title[ my_language ] );
By changing the language variable to 'other_language' you would be accessing a totally different set of data. I know the above is a very simplified example of a language file and it's useage... and this might not even pertain to what you are looking for. I do, however, hope that it helps someone.
03-15-2011 04:31 PM
Yes, this is pretty much exactly the manner I'll be using the information! Thanks for the support!
03-15-2011 04:59 PM
I'd still recommend using Embed() with that though, so you can keep the data in an external file, but then parsing it as XML at runtime. It might be easier to maintain or manage than doing what amounts to hardcoding it inside a source file.