调用javascript函数并传入回调函数
我想在动作脚本中调用一个javascript函数,如下所示:调用javascript函数并传入回调函数,javascript,flash,Javascript,Flash,我想在动作脚本中调用一个javascript函数,如下所示: ExternalInterface.call('a_js_function', param1, another_js_function); function a_js_function(testStr, callback) { console.log(testStr); callback(testStr); } function another_js_function(str) { console.log(
ExternalInterface.call('a_js_function', param1, another_js_function);
function a_js_function(testStr, callback) {
console.log(testStr);
callback(testStr);
}
function another_js_function(str) {
console.log(str);
}
我想要一个javascript函数a_js_函数接受两个参数,一个是字符串,另一个是回调函数。所以我可以这样调用js函数:
ExternalInterface.call('a_js_function', param1, another_js_function);
function a_js_function(testStr, callback) {
console.log(testStr);
callback(testStr);
}
function another_js_function(str) {
console.log(str);
}
正确的方法是什么
问题解决了,结果是我传入的第二个字符串,在javascript中,我必须将字符串转换为函数才能调用它。这样调用
try {
ExternalInterface.call('a_js_function', param1, another_js_function);
} catch(e:Error) {
trace(e)
}
有关更多信息,请参见,因为flash没有对javascript函数的任何引用
另一个_js_函数
,您需要将函数名作为字符串传递,然后使用任意名称空间上的括号访问它。为了简单起见,我使用了全局变量,但它可以是任何对象/名称空间
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");
行动中:您尝试过吗?你得到了什么结果?@zzzzBov它没有调用另一个_js_函数。下面的答案幸运吗?