title: How to unescape Unicode character in ActionScript 3 AS3
body: <p>I'm having a problem with "&amp;".</p>
  
  <p>Basically I haven't been able to escape this correctly in Flash AS3, however I did find this link which seems helpful:
  <a href="http://www.smithmediafusion.com/blog/?p=343" rel="nofollow">http://www.smithmediafusion.com/blog/?p=343</a></p>
  
  <p><strong>Test page:
  <a href="http://touchstormdigital.com/leon/testing/" rel="nofollow">http://touchstormdigital.com/leon/testing/</a></strong></p>
  
  <p>Here are my current functions:</p>
  
  <pre><code>try {
      varHome   = this.loaderInfo.parameters.home;
      homeImage = this.loaderInfo.parameters.homeImage;
      homeTitle = this.loaderInfo.parameters.homeText; // Get the Video Title
      // Title  = "Quick &amp; easy chicken recipes for dinner"
  } catch (e:Error) {
      varHome   = "false";
      homeBool  = false;
  }
  </code></pre>
  
  <p>The Search and Replace function:</p>
  
  <pre><code>// Home player test search &amp; replace ampersand
  private function replaceString(str:String, find:String, replace:String):String 
  {
      var startIndex:Number = 0;
      var oldIndex:Number   = 0;
      var newString:String  = "";
  
      while ((startIndex = str.indexOf(find, startIndex)) != -1)
      {
          newString += str.substring(oldIndex, startIndex) + replace;
          oldIndex = startIndex += find.length;
      }
  
      return((newString == "") ? str : newString);
  }
  </code></pre>
  
  <p>And then how I'm using it</p>
  
  <pre><code>private function drawSplash():void
  {
      sp = new ScreenButton();
  
      replaceString(homeTitle,"&amp;", "\\u0026");
  
      sp.drawScreenButton(playerW, playerH, homeBool, homeImage, homeTitle);
      sp.addEventListener("onPlay", vd.playVideo);
      sp.addEventListener("embedSplash", hideSplash);
      stage.addChild(sp);
  }
  </code></pre>
  
  <p>I think this is where the problem is:</p>
  
  <pre><code>replaceString(homeTitle,"&amp;", "\\u0026");
  </code></pre>
  
  <p>I've also tried this:</p>
  
  <pre><code>replaceString(homeTitle,"&amp;", String.fromCharCode(38));
  </code></pre>
  
  <hr>
  
  <p><strong>GOAL</strong>
  Grab "Quick &amp; easy chicken recipes for dinner" and display it</p>
  
  <p>Still displaying just "Quick"</p>
  
  <p><strong>Test page:
  <a href="http://touchstormdigital.com/leon/testing/" rel="nofollow">http://touchstormdigital.com/leon/testing/</a></strong></p>
  
  <hr>
  
  <p><strong>UPDATE! Another simple fix found and no need to change title!</strong></p>
  
  <p>In addition to The_asMan's answer which works, but requires the text/copy to be written all weird, I found this simple piece of javascript that does the job:</p>
  
  <p><a href="http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp" rel="nofollow">http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp</a></p>
  
  <p><strong>How I'm using it:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      var homeText = "Quick &amp; easy - chicken' recipes for dinner?!=+";
      var fixed = encodeURIComponent(homeText);
  
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>And then in the Flashvars area:</strong></p>
  
  <pre><code>so.addVariable("homeText", fixed);
  </code></pre>
  
  <p><strong>Then in Flash:</strong></p>
  
  <pre><code>unescape(homeTitle);
  </code></pre>
  
  <p><strong>Woot!</strong></p>