2017-08-22 168 views
0

我有数组列表,并在这个数组有4个URL和端口,我想要当用户连接从索引[0]然后连接丢失我显示按钮时,单击用户这个按钮我想连接相同的端口,但像索引第二个网址[ 1]。as3如何使用交换数组列表?

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

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) 
     ]; 

任何帮助将是巨大的,我需要的伪代码

+0

1)保持一个当前选择和你失去了连接每一次指数,增加它。检查索引是否小于数组长度。 2)保持使用索引0,但每次丢失连接时,将第一个元素从列表中移动到结尾。 'urisToTry.push(urisToTry.shift())' – 3vilguy

+0

谢谢你的回答你有没有伪代码? @ 3vilguy – KaraEski

+1

恩,是: '当连接丢失时:' 'getNextUrl;' '使用新网址连接;'' – 3vilguy

回答

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