开发者

How to prevent browser from becoming non-responsive when ExternalInterface.call is called?

I have a flash movie and I am using ExternalInterface.call function to call a javascript function from within the movie. The problem is that whenever the javascript function gets executed in Mozilla Firefox, the browser becomes non-responsive. I have uploaded the file here: http://www.aakashb.0fees.net/carbon6.html This is a map of India and a javascript function in called when you click on the top-most state (that's the state of Jammu and Kashmir ). Open it in a new window...it might make your browser non-r开发者_StackOverflowesponsive too.


there're two mistakes in your approach:

  1. you can call javascript function directly from ExternalInterface.call.

    so there's no need to call eval in your javascript code.

    ExternalInterface.call('alert', "alert from swf!");

  2. alert will block the execution of javascript codes

try this code:

alert(1);
console.log(1); // execution of this line is blocked by 'alert'
alert(2);
console.log(2); // execution of this line is blocked by 'alert'

so, if you eval 'alert', the execution of code is blocked and your browser may be non-responsive.
this will be avoided very easily. change your javascript function 'evaluate' as follows

function evaluate(code) {
    setTimeout(function () {
        eval(code);
    }, 0);
}

settimeout will simply postpone the execution of 'alert' and return the callback from actionscript as soon as possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜