Calling a Namespaced JavaScript Function from Flas

2019-06-01 03:56发布

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);

2条回答
Anthone
2楼-- · 2019-06-01 04:42

Yes. Yes you can.

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-01 04:43

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 ...

查看更多
登录 后发表回答