2

次の関数を使用して、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 で可能ですか? もしそうなら、どのように?変数を宣言し、設定し、関数に渡すにはどうすればよいですか? ありがとう!

4

1 に答える 1

1

のようなもの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);
}

これは、eg (偽の引数) を呼び出すことを意味します。

myNetConnection.connect("mycommand", 1, true, "hello");

からのこの呼び出しに相当するものは次のonNetStatusとおりです。

super.connect("mycommand", 1, true, "hello");

詳細.apply()http ://adobe.ly/URss7b

于 2012-11-19T23:17:37.520 に答える