Screenweaver HX, file I/O and UTF8: A cautionary tale
Thursday, February 1st, 2007As I mentioned in a previous post, I’ve been using Screenweaver HX to build a little seat-planning app. Well, thinks got a point today where I was ready to start importing the client’s list of attendees (an Excel sheet, naturally). So I decide to go the time honoured route of exporting a tab-separated text file and parsing that in Flash, after getting the contents in via a file open call in the haXe backend (file I/O in Flash! Hurrah!). However, as soon as I do this, Flash chokes on the import.
Now this is weird, becuase I’d been using exactly the same file open stuff to get in my development testing data (a nice, sane XML file) and the app had been playing just fine. Long story short, after banging my head against a brick wall for a few hours (even to the point of offloading all the parsing to the backend, and passing a neatly parsed array to the hosted SWF, which also failed), I figured out that Flash was choking because the offending text file wasn’t UTF-8 encoded. A quick insertion of this line:
content = neko.Utf8.encode( content );
into my file opening method in the backend solved all my problems and I could loosen my jaw muscles again :)
So, the moral of this story is (besides always read the friggin’ docs) is: if you’re doing text file I/O in Screenweaver, always make sure you UTF-8 encode before handing it over to Flash. Here endeth today’s lesson.