Just goes to show you you can teach an old dog new tricks. (Yes, old. I turned 40 the other day.) Here’s something I never knew you could do: load a plain text file in to Flash.
There are a number of types of files you can load into Flash – swfs, jpgs, xml, stylesheets, and LoadVars, to name a bunch. I never knew of a way of simply loading a plain text file though. LoadVars is the closest, but after loading, it is broken down into name/value pairs. My solution in the past was to preface the text file with a variable name and pull the text out of the variable: “info=blah blah blah”, then grab myLoadVars.info.
But, as I was perusing the Flash help files a couple of weeks ago, I came across an example of loading straight text. Basically, you use the LoadVars object, and the onData event. The onData handler gets passed a string of the data loaded. To quote: “A string or undefined; the raw (unparsed) data from a LoadVars.load() or LoadVars.sendAndLoad() method call.”
This allows you to load text in any format – html, css, csv, xml, you name it, and then do your own parsing on it. Opens up a lot of possibilities.
I know, I know, it’s not a new, undocumented feature that I just discovered or anything. Just kind of cool, and it surprises me that after five years of living and breathing Flash, there are still relatively major (and useful) things like this that I have missed.