Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用javascript函数并传入回调函数_Javascript_Flash - Fatal编程技术网

调用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(

我想在动作脚本中调用一个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(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_函数。下面的答案幸运吗?