Archive

Archive for March, 2009

ExternalInterface Error When Parameters Contain Special Characters

March 11th, 2009 Comments off

I ran into a problem today when using ExternalInterface in and ActionScript 3 project. The issue occurred in both Internet Explorer and Firefox. In the project, I was using ExternalInterface.call() to execute a JavaScript function, and passing a long text string as a parameter. The long text string happened to contain a bunch of new lines and slashes. In both browsers a JavaScript error was generated, and the error was not catch-able by a try…catch block in the Flash application. After some searching I found a blog post on Mike Chamber’s site about a known bug in the Flash plugin. The solution is to use String.replace() to sanitize the string before executing ExternalInterface.call().

stringParameter = stringParameter.replace(/n/g, " ");
stringParameter = stringParameter.replace(/r/g, " ");
stringParameter = stringParameter.replace(/\/g, "\\");