

ExternalInterface Bug with new line chars
source link: http://www.mikechambers.com/blog/2006/01/10/externalinterface-bug-with-new-line-chars/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ExternalInterface Bug with new line chars
Tuesday, January 10, 2006
A couple of days ago I ran into a bug with ExternalInterface which caused me quite a hassle (a couple of people ran into it before I did). I finally figured it out, and wanted to post here in case anyone else runs into it.
Basically, if the data being passed from JavaScript to ActionScript or ActionScript to JavaScript via ExternalInterface contains any line returns (\n) then the string is not serialized correctly, and the call will fail (you will probably see a JavaScript error). This affects both Flash Player 8, and the Flash Player 8.5 alpha.
The issue has been logged and is being looked at it. Luckily, there is a simple workaround, which is to manually escape the line returns by replace \n with \n.
Here is how to do it in ActionScript 3:
var data:String = stringToPass.replace(/\n/g, "\\n" );
and here is how to do it in ActionScript 2:
function escapeLineReturns(s:String):String
{
trace("a");
var len:Number = s.length;
var sb = "";
var c;
for(var i:Number = 0; i < len; i++)
{
c = s.charAt(i);
if(c == "\n")
{
sb += "\\n";
}
else
{
sb += c;
}
}
trace("r : " + sb);
return sb;
}
var data:String = escapeLineReturns(stringToPass);</pre>
On the JavaScript side you can basically use the same solution as in ActionScript 3.0:
var data = stringToPass.replace(/\n/g, "\\n" );
Recommend
-
31
-
40
I tried to reset my password to a random alphanumeric string, 64 characters in length. Initially, my password only had lower case letters and numbers. Zoom refused to allow me to use this string because it didn’t h...
-
23
Macromedia Podcast #3 and the new Maelstrom ExternalInterface API Thursday, July 28, 2005 We have just posted the Third Macromedia De...
-
14
Copy link Contributor klensy commented
-
10
Copy link Contributor Herschel...
-
3
One line of code (JS) (33 Part Series) const htmlSpecialChars = str => str.replace(/[&"'<&g...
-
6
Conversation The PR implements DoubleEndedIterator trait for ToLowercase and ToUppercase. This enables reverse iteration of lowercase/uppercase variants...
-
10
New issue [chars_next_cmp] Fix unescaped suggestion #8376
-
8
Copy link Contributor thomcc commented...
-
4
Fuck 80 Chars Limit – It is 2021 now 2021-06-06 :: 荒野無燈 :: Mod 2021-06-07(accd477) #coding-style #8...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK