从Flash调用命名空间JavaScript函数 [英] Calling a Namespaced JavaScript Function from Flash

查看:180
本文介绍了从Flash调用命名空间JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  // JavaScript 
foo.bar =函数可以使用ExternalInterface来调用命名空间的JavaScript函数吗? (baz){}

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


解决方案> ExternalInterface的文档。调用是有点误导。它声明第一个参数必须是一个函数名,这不是全部的事实。它可以是任何可以被评估为proprer JS表达式的字符串。实际上,

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

相当于

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

所以你可以做下面的事情:

($ {pre> ExternalInterface.call(function(foo){alert(foo); return true;},test);

此技术有时用于 Flash JS注入。希望这个澄清的事情...


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

解决方案

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

这篇关于从Flash调用命名空间JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆