在AS3方法中接受多个参数 [英] Accept multiple arguments in an AS3 method

查看:263
本文介绍了在AS3方法中接受多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何接受自定义方法中的多个参数?像:

 代理(101,2.02,303); 

函数Proxy(args:Arguments){
Task(args);


函数任务(var1:int,var2:Number,var3:String){
//使用变量
}

解决方案

你不能像刚才那样通过args数组题。

 函数Proxy(... args)
{
//简单,没有错误检查。
Task(args [0],args [1],args [2]);

更新 $ b

阅读其中一条评论之后,看起来好像可以避开:

  function Proxy ... args)
{
//简单,没有错误检查。
Task.apply(null,args);

//呼叫也可以是Task.apply(this,args);
}

请小心。 apply()的性能比用传统方法调用函数要慢得多。


How do I accept multiple arguments in a custom method? Like:

Proxy(101, 2.02, "303");

function Proxy(args:Arguments){
    Task(args);
}

function Task(var1:int, var2:Number, var3:String){ 
    // work with vars
}

解决方案

You wouldn't be able to just pass the args array through like you have in your question. You'd have to pass each element of the args array seperately.

function Proxy(... args)
{
   // Simple with no error checking.
   Task(args[0], args[1], args[2]);
}

Udate

After reading one of the comments, it looks like you can get away with:

function Proxy(... args)
{
    // Simple with no error checking.
    Task.apply(null, args);

    // Call could also be Task.apply(this, args);
}

Just be careful. Performance of apply() is significantly slower than calling the function with the traditional method.

这篇关于在AS3方法中接受多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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