This content has been marked as final. Show 7 replies
Are you sure that the external text files is saved as UTF-8?
In the testing environment, after the file is loaded, go Debug-> List Variables. Does it show correctly there?
I'm not sure how to save as UTF-8 from Notepad. I have examined the file (words.txt) in a hex-editor, and every character is represented with the correct ASCII value (using the url-encoded version of words.txt).
Using only English characters everything works fine. I can use <space> as well as the url-encoded +. Both work fine and produce the same output.
Using Debug -> List Variables shows exactly the same content as the (erroneous) output from the program. The "character" with code 65533 is represented as a square in the output and using List Variables.
Okay. Using the List Variables is sort of a good check point. If it shows right there then you know the problem is with how you are displaying the info and the embedding of Latin 1 (or additional characters) will be most likely be the solution.
That it isn't showing properly there means the problem is with the file or the reading part. The best and easiest solution would be to figure out how to save the file as UTF-8. Flash really likes that. I'm on a Mac so I can't tell you how to do it from Notepad, but on TextEdit (the Mac analog) I would do a save as and there would be a drop down to allow me to select different formats. I imagine there is something similar in Notepad.
If you can't do it, or you are interfacing with some other web technology that doesn't speak unicode, I'm not sure I know how to help you. Have you tried using unescape()? I played around with the letters – loading them in as unicode and then doing escape(). I found that Flash would encode them as:
So I'm thinking that Flash uses a different urlencoding scheme that some other systems. Really unicode is a good thing.
Also just as a note, you might want to use LoadVars class instead of the old-school loadVariables. LoadVars has a very nice onLoad event that you can use instead of having to keep checking if the file has loaded. And depending you might even want to change the word list into an XML document.
Sometimes you just need reminding!
Having used Notepad a lot I have never cared about the "Save as" option - but there it was "Save as UTF-8". I did and it worked, that is if I used the keyboard version, not if using the url-encoding.
Thanks a lot.
Your suggestion about an XML-input is worth considering, allthough I need for other people to be able to write their own input file. Almost everybody will be familiar with Notepad, and can understand instructions about "Save as UTF-8". Trusting them to do a correct XML file, well I think that is a little too complex for the people I have in mind.
Thanks again for your time and interest
Glad that worked. If you are going to have other people make their own files I would definitely look into using LoadVars. I know a lot of truly lovely people, but if a few XML tags are above their heads, then &done="done" will probably do a few of them in as well! I promise that it will happen as:
and so on.
Thanks for the help and for pointing to a problem in my solution. I have done some thinking and reading and ended with this:
I am reading the external text file (in UTF-8 format) as an XML file.
Tricking Flash to do so gets me a single node as a string containing the entire text file. This string can then be parsed. The external text file then can be much simpler - a single word or phrase on its own line.
The reading and control of loading is then done with the XML object's load and onLoad methods.
I owe this solution to Edwin Heijmen from the book: Flash Hacks by Sham Bangal (O'Reilly publishing Co.), where it is hack no. 85:
(with a couple of my changes - on a Windows system a new line i s marked by two characters (\r \n) so you have to step two forward for the next starting index - not one as in the recipe. I also use the Array.push() in favor of explicitly assigning the value to a specific index.
Nice solution. Just want to point out that hacks such as that are a bit sloppy. Probably best when you alone will be creating the files. But if others do, can you be sure they won't create the text file on a Linux machine? Just be careful…