Why does ExternalInterface breaks when I pass parameter with JSON like string?

前端 未结 2 1388
逝去的感伤
逝去的感伤 2021-02-13 10:55

I have a very odd problem with Flash 10 and ExternalInterface. I am currently using a homemade bridge to use RTMFP with Javascript and whenever I try to pass data that contains

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-13 11:25

    Admittedly this wouldn't work directly for output to the console in Firebug, but for most other applications (i.e. sending a potentially 'invalid' string to Javascript), escape and unescape should work just fine:

    AS3:

    var testString:String = "\"\\\"\"";
    ExternalInterface.call("showString", escape(testString));
    

    And then in Javascript:

    function showString(msg) {
        console.log(unescape(msg));
        document.getElementById('messagebox').innerHTML = unescape(msg);
    }
    
    

提交回复
热议问题