我想在Action script中调用一个javascript函数,如下所示:
ExternalInterface.call('a_js_function', param1, another_js_function);我希望javascript函数a_js_function有两个参数,一个是字符串,另一个是回调函数。所以我可以像这样调用js函数:
function a_js_function(testStr, callback) {
console.log(testStr);
callback(testStr);
}
function another_js_function(str) {
console.log(str);
}执行此操作的正确方法是什么?
问题解决了,原来我传入的第二个参数是一个字符串,在javascript中,我必须将字符串转换为函数才能调用它。
发布于 2013-08-16 01:34:30
像这样打电话
try {
ExternalInterface.call('a_js_function', param1, another_js_function);
} catch(e:Error) {
trace(e)
}有关更多信息,请参阅this
发布于 2013-08-16 01:39:06
由于flash没有任何对javascript函数another_js_function的引用,因此需要将函数名作为字符串传递,然后使用括号在任何名称空间中访问它。为简单起见,我使用了全局变量,但它可以是任何对象/名称空间
another_js_function = function(testStr) {
alert(testStr);
}
a_js_function = function(testStr, callback) {
console.log( this.window );
window[callback].call(this, testStr); // pass scope?
// OR
window[callback](testStr);
}
// Simulating call from Flash
a_js_function("howdy y'all", "another_js_function");https://stackoverflow.com/questions/18257964
复制相似问题