Display special characters in Flash – use URL Encoding

August 15th, 2005

    Recently I had to load the text from external source in Flash and from the design of the application I had to rely on LoadVars command.

    No wonder, that quite soon I came up with a problem that Flash does not display special characters like “+”, “%” or “&” if those characters are loaded into Flash via LoadVars. After a bit of research, I found out that LoadVars object method “load” operates with URL encoded strings to allow to include those special characters into string of text.

    A good reference table with URL Encoding table for special characters can be found here at
Flash TechNote URL Encoding: Reading special characters from a text file.

The more extensive list of Unicode escape sequence codes in PDF format can be obtained from Unicode.org.

Therefore in Flash,

  • Symbol “%” becomes %25 after URL encoded
  • Symbol “&” becomes %26 after URL encoded
  • Symbol “+” becomes %2B after URL encoded
  • and so on…

    In ActionScript code:

    this.createTextField(“result_ta”,1, 0,0,150,20);
    result_ta.embedFonts =false;

    var myData_lv = new LoadVars();
    myData_lv.load (“myText.txt”);
    myData_lv.onLoad = function()
    result_ta.text = myData_lv.sp1_title_1;

    Content of “myText.txt”:

    &sp1_title_1=Andrew %26 Stas have gained a 5%25 percentage raise %2b good vacation bonus

        As a concluding note, an extensive paragraph on how to work with special characters in Flash 6 and higher is written at PDF file:“Using ActionScript in Flash” (Page 118 “Working with text”)