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

as3 How to use swap with array list?

我有数组列表,在这个数组中有 4 个 url 和端口,我想当用户从索引 [0] 连接然后连接丢失时我显示按钮当点击用户这个按钮我想连接相同端口但第二个 url 像 index[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)
        ];

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

像这样:

// 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();
}