as3 如何使用数组列表进行交换?

问题描述 投票:0回答:1

我有数组列表,在这个数组中有4个url和端口,我希望当用户从索引[0]连接时连接丢失,当单击用户此按钮时我显示按钮我想连接相同的端口但第二个url如索引[1 ].

我如何解决,我该怎么做,请帮忙,谢谢。这是我的清单

private static var urisToTry:Array = [
            new SocketUri("123.net", 123),
            new SocketUri("1234.net", 123),
            new SocketUri("123.net", 321),
            new SocketUri("1234.net", 321)
        ];

任何帮助都会很棒我需要伪代码

arrays actionscript-3
1个回答
0
投票

类似这样的:

// current array index
private var connIndex:int = 0;

public function connect():void
{
    var mySocketURI:SocketUri = urisToTry[connIndex];

    // do your connection here
}

private function onConnectionLost():void
{
    // increase index and check if it is within array length
    if(connIndex >= urisToTry.length -1)
        connIndex = 0;
    else
        connIndex++;

    connect();
}
© www.soinside.com 2019 - 2024. All rights reserved.