将函数传递给 Actionscript 3 中的另一个函数 [英] Passing a function to another function in Actionscript 3

查看:22
本文介绍了将函数传递给 Actionscript 3 中的另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数将一个数组作为参数传递给另一个函数,这个数组中有多种数据类型,但我想知道如何传递一个函数或一个函数的引用,以便另一个函数可以调用它任何时候.

I have a function that passes an array to another function as an argument, there will be multiple data types in this array but I want to know how to pass a function or a reference to a function so the other function can call it at any time.

例如

函数A:

add(new Array("hello", some function));

功能B:

public function b(args:Array) {
    var myString = args[0];
    var myFunc = args[1];
}

推荐答案

只需将函数名作为参数传递,不是,就像在 AS2 或 JavaScript 中一样?

Simply pass the function name as an argument, no, just like in AS2 or JavaScript?

function functionToPass()
{
}

function otherFunction( f:Function )
{
    // passed-in function available here
    f();
}

otherFunction( functionToPass );

这篇关于将函数传递给 Actionscript 3 中的另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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