I have javascript code that splits the screen, however, how do I run it from a flex application?

So, this code splits the screen into two frames:


I need to run this code from a flex application and what I am doing is:

   var jsFunc:String = "function () { location.href=\"javascript:A14nH=location.href; L3f7=\"http://www.google.com\";R1Gh7=\"http://www.google.com\";if(L3f7&&R1Gh7){Fr4Q=\"<frameset%20cols=\"*,*\">\n<frame%20src=\"\"+L3f7+\"\"/>\";Fr4Q+=\"<frame%20src=\"\"+R1Gh7+\"\"/>\n\";Fr4Q+=\"</frameset>\";with(document){write(Fr4Q);void(close())}}else{void(null)}\"}";
   var divExists:Boolean = ExternalInterface.call(jsFunc);

Can someone tell me what's wrong?

(Btw, if you change var jsFunc:String = "function () { location.href='http://www.google.com' }"; the page does take you to Google)


Make sure your "allowNetworking" parameter of the object and embed tags of Flash is set to true. With that parameter, the whole ExternalInterface package becomes severely limited.

Also, it may be a better idea to store the javascript along with the HTML. Then, from AS3, you can call the js function using ExternalInterface.

IN ActionScript: ExternalInterface.call(myJavascriptFunc) will call myJavascriptFunc if it is loaded in the same page as the Flash application.

I believe you can call the eval function and pass it the JavaScript you want it to execute:

var jsFunc:String = "location.href=\"javascript:A14nH=location.href; L3f7=\"http://www.google.com\";R1Gh7=\"http://www.google.com\";if(L3f7&&R1Gh7){Fr4Q=\"<frameset%20cols=\"*,*\">\n<frame%20src=\"\"+L3f7+\"\"/>\";Fr4Q+=\"<frame%20src=\"\"+R1Gh7+\"\"/>\n\";Fr4Q+=\"</frameset>\";with(document){write(Fr4Q);void(close())}}else{void(null)}\"";
var divExists:Boolean = ExternalInterface.call("eval", jsFunc);

Try removing the first location.href assignment and leave the code you want executed:

var jsFunc:String = "function () {
    lA14nH = location.href;
    L3f7 = \"http://www.google.com\";
    R1Gh7 = \"http://www.google.com\";

    if (L3f7 && R1Gh7) {
        Fr4Q = '<frameset%20cols=\'*,*\'>\n<frame%20src=\''+L3f7+'\'/>';
        Fr4Q += '<frame%20src=\''+R1Gh7+'\'/>\n';
        Fr4Q += '</frameset>';

        with (document) {
    else {
var divExists:Boolean = ExternalInterface.call(jsFunc);

  1. You are not escaping quotes propertly.
  2. ExternalInterface.call() expects a javascript statement to execute - you're passing the definition of a function, but not calling it. As already suggested, append a () to the end to call the passed function.

I believe I've escaped the quotes properly. Try this and let me know what happens.

var js:String = "function () { ";
js += "location.href=\"";
js += "javascript:A14nH=location.href;";
js += "L3f7 = \"http://www.google.com\";";
js += "R1Gh7 = \"http://www.google.com\";";
js += "if(L3f7&&R1Gh7){ ";
js += "Fr4Q= \\\"";
js += "<frameset cols='*,*'><frame src='\\\" + L3f7 + \\\"'/>\\\"; ";
js += "Fr4Q+=\\\"<frame src='\\\" + R1Gh7 + \\\"'/>\\\"; ";
js += "Fr4Q+=\\\"</frameset>\\\"; ";
js += "with(document){write(Fr4Q);void(close())} ";
js += "}else{void(null);} "
js += "\"} ()";
var divExists:Boolean = ExternalInterface.call(js);

If you pass


to ExternalInterface.call, it will execute it and you'll get an alert. But if you pass


it just creates an anonymous function. To call the function, you have to add () to it as in


This is same as creating a named function and calling it like:

function test(){alert('something');}

you can even pass parameters this way:

"function(text){alert('Got ' + text);('taDaa!!')}"

Need Your Help

'Locale' configuration and its relationship with Windows API

windows api configuration locale createfile

Can the locale configuration of a system OR the keyboard type configuration of that system in anyway affect which API is called at the Kernel level? To be specific, if a program is invoking 'Create...