的更多信息
我有一个继承自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 中可能吗? 如果是这样,如何? 我将如何声明变量,设置它,将其传递给函数等? 谢谢!
在 connect
中是这样的
...
// 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);
}
这意味着调用例如(虚假参数):
myNetConnection.connect("mycommand", 1, true, "hello");
将导致来自onNetStatus
的此调用:
super.connect("mycommand", 1, true, "hello");
关于 .apply()
: http://adobe.ly/URss7b