I had an issue with sending flash variables through to a JavaScript function as the “escape” function just Unicodes the variable and JavaScript parses the string as a decoded string before sending pushing it through the function and messes everything up.
After doing some digging on the internet I found a str_replace function that was originally written for AS2 (ActionScript 2), I changed the code to be compatible for AS3(ActionScript 3).
Flash str_replace function.
public function str_replace (findme : String, Replace : String, str : String){
var new_str = "";
for (var i = 0; i < str.length; i++)
{
if (str.charAt (i) == findme)
{
trace("Found string");
trace(Replace);
new_str += Replace;
}
else
{
new_str += str.charAt (i);
}
}
return new_str;
}
Usage:
trace(str_replace(”‘”,”\\’”,MyTextBox.text));
MyTextBox.Text is an input textbox but as I am sure you are aware it will work with all string variables.








