Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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
Actionscript 3 在AS3中,如何存储、检索和重用省略号(…)参数提供的参数?_Actionscript 3_Apache Flex_Syntax_Flash - Fatal编程技术网

Actionscript 3 在AS3中,如何存储、检索和重用省略号(…)参数提供的参数?

Actionscript 3 在AS3中,如何存储、检索和重用省略号(…)参数提供的参数?,actionscript-3,apache-flex,syntax,flash,Actionscript 3,Apache Flex,Syntax,Flash,我有一个从NetConnection继承的类,具有以下函数: override public function connect(command:String, ... arguments):void { addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); super.connect(command, arguments); } 我想做的是: override public function connect(comm

我有一个从NetConnection继承的类,具有以下函数:

override public function connect(command:String, ... arguments):void
{
    addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
    super.connect(command, arguments);
}
我想做的是:

override public function connect(command:String, ... arguments):void
{
    m_iTries = 0;
    m_strCommand = command;
    m_arguments = arguments;
    addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
    super.connect(command, arguments);
}

private function onNetStatus(pEvent:NetStatusEvent):void
{
    if (/* some logic involving the code and the value of m_iTries */)
    {
        super.connect(m_strCommand, m_arguments);
    }
    else
    {
        // do something different
    }
}

这在AS3中可能吗?如果是,怎么做?如何声明变量、设置变量、将变量传递给函数等。?谢谢

类似于
连接中的内容:

 ...
 // Add m_strCommand to the start of the arguments array:
 m_arguments.unshift(m_strCommand); 
 ...
onNetStatus中:

if (/* some logic... */)
{
    // .apply calls the function with first parameter as the value of "this". 
    // The second parameter is an array that will be "expanded" to be passed as 
    // if it were a normal argument list:
    super.connect.apply(this, m_arguments);
}
super.connect("mycommand", 1, true, "hello");
这意味着调用例如(伪参数):

将导致来自
onNetStatus
的呼叫金额:

if (/* some logic... */)
{
    // .apply calls the function with first parameter as the value of "this". 
    // The second parameter is an array that will be "expanded" to be passed as 
    // if it were a normal argument list:
    super.connect.apply(this, m_arguments);
}
super.connect("mycommand", 1, true, "hello");

更多关于
.apply()

你是说上面的代码不起作用吗?我从未尝试过,但您上面的代码是我所期望的工作方式。
arguments
参数是一个
数组
,因此您只需声明一个成员变量(private var m_argument:Array),并按原样分配它。唉,看似简单的东西实际上可能不起作用:)看起来不可能起作用。谢谢你!“如果您传递数组类的一个实例,那么整个数组将被放置在…(rest)参数数组的单个元素中。”好的,我现在明白了,谢谢您的解释。。。现在我明白了,我们来考虑一下:)您需要使用Function.apply()使其按编写的方式工作,例如
super.connect.apply(super,m_参数)-允许您传递数组,就像传递参数列表一样。不过请注意,在将“command”传递给super.connect.apply之前,您必须将其添加到数组中。@TheKaneda很好的调用,您应该将其作为答案发布!