Calling a Namespaced JavaScript Function from Flash

五迷三道 提交于 2019-12-23 02:13:13

问题


Can I use ExternalInterface to call a namespaced JavaScript function?

//JavaScript
foo.bar = function(baz) {}

// AS3
import flash.external.ExternalInterface;
ExternalInterface.call('foo.bar', baz);

回答1:


The documentation of ExternalInterface.call is a little misleading. it states the first parameter must be a function name, which is not the whole truth. it can be any string that can be evaluated as a proprer JS expression. In fact

ExternalInterface.call(func, param_1, ... , param_n);

is equivalent to

eval(func)(param_1, ... , param_n);

so you may just as well do the following

ExternalInterface.call("function (foo) { alert(foo); return true; }","test");

this technique is sometimes used for Flash JS injection. hope this clarifies things ...




回答2:


Yes. Yes you can.



来源:https://stackoverflow.com/questions/2230869/calling-a-namespaced-javascript-function-from-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!