在ActionScript 3中传递函数到另一个函数 [英] Passing a function to another function in Actionscript 3

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

问题描述

我有一个函数传递一个数组到另一个函数作为参数,将有多个数据类型的数组,但我想知道如何在一个函数或引用传递给一个函数,所以其他的功能,可以把它随时

恩。

功能的:

 添加(新的Array(你好,有的功能));
 

函数B:

 公共函数b(参数:数组){
    VAR MyString的=的args [0];
    变种myFunc的=的args [1];
}
 

解决方案

简单函数名作为参数传递,没有,就像在AS2或JavaScript?

 函数functionToPass()
{
}

功能otherFunction(F:功能)
{
    //可以在这里传递函数
    F();
}

otherFunction(functionToPass);
 

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.

ex.

function A:

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

function B:

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

解决方案

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天全站免登陆