简体   繁体   English

as3数组到参数类/指针函数

[英]as3 array to parameters class / pointer function

I had a little trouble. 我有点麻烦 My case -> I want to set Array as a parameter for caling function/class. 我的情况->我想将Array设置为校准函数/类的参数。

var letters:Array = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
letters.sort(randomSort);

and call function 和通话功能

inGame(no1,no2,no3,no4,no5,no6,no7,no8,no9,no10);

my function 我的功能

public function inGame(_soal1: String,_soal2: String,_soal3: String,_soal4: String,_soal5: String,_soal6: String,_soal7: String,_soal8: String,_soal9: String,_soal10: String,) 
{
   ......
}

The problem -> I cant set array become a parameter for function inGame. 问题->我无法设置数组成为inGame函数的参数。 Its getting error 1136 when i try like this: 当我这样尝试时,它会收到错误1136:

inGame(letters); inGame(字母);

any solution for my case?? 我的情况有什么解决办法吗? thankyou 谢谢

In addition to Frank's suggestion, personally I would create another function and call that one with appropriate arguments: 除了弗兰克的建议之外,我个人将创建另一个函数并使用适当的参数调用该函数:

public function inGame(...args):void {
    this._inGame.apply(this,(args.length && args[0] is Array) ? args[0] : args);
    /*
    // shorthand for:
    if (args.length && args[0] is Array) {
        this._inGame.apply(this, args[0]);
    } else {
        this._inGame.apply(this, args);
    }
    */
}

private function _inGame(
           _soal1:String, _soal2:String,
           _soal3:String, _soal4:String,
           _soal5:String, _soal6:String,
           _soal7:String, _soal8:String,
           _soal9:String, _soal10:String):void {
    // here's your code
}

You should just rewrite your inGame() function : 您应该只重写inGame()函数:

public function inGame(letters:Array):void
{
    // do something with letters
}

Unless you have some quality unknown reason not to do this, you are just complicating something rather simple. 除非您有一些质量未知的理由不这样做,否则您只会使事情变得非常简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM