2017-08-17 2 views
1

私は接続が失われたときにconnectAgain関数を持っています私はこのボタンをクリックするとaddchildボタンを呼び出しますこの関数のconnectAgain関数を呼び出すにはserverUrlとserverPort現在のシステムとその作業です。AS3 - 次の配列を取得する方法インデックスとどのように私の関数を変更する

しかし、今、私は4または5のIPとポートを持っています。私は配列や辞書やオブジェクトを追加して、接続が失われたら、私はボタンをクリックしてIPとポートを呼び出すが、すべての接続は次のIPとポートに同じIPとポートを呼び出さないようにする。

おかげで、これは私の現在の関数である私を助けてください。どうすればいいですか?次のように

public static function connectAgain(serverUrl:String = "", serverPort:int = 0):void { 


     serverUrl = myGameClass.serverUrl; 
     serverPort = myGameClass.serverPort; 


    } 

答えて

1

あなたは、いくつかのヘルパークラスを使用することができます。

あなたはイテレータを作成initのどこか
class UriIterator { 
    private var _availableAddresses: Vector.<UriVO> = new Vector.<UriVO>(); 

    public function withAddress(host: String, port: int): UriIterator { 
     const a: UriVO = new UriVO(host, port); 
     _availableAddresses.push(a); 
     return this; 
    } 

    public function get next(): UriVO 
    { 
     return _availableAddresses.length ? _availableAddresses.pop() : null; 
    } 
} 

class UriVO { 
    private var _host: String; 
    private var _port: int; 
    public function Address(host: String, port: int) { 
     _host = host; 
     _port = port; 
    } 

    public function get host():String { 
     return _host; 
    } 

    public function get port():int { 
     return _port; 
    } 
} 

は:

... 
const urisToTry: UriIterator = new UriIterator() 
     .withAddress("http://urlone.com", 1211) 
     .withAddress("http://urltwo.com", 1212) 
     .withAddress("http://urlthree.com", 1213) 
     .withAddress("http://urlfour.com", 1214) 
... 

その後、再接続機能であなたにnext()関数を呼び出すことができます接続のために次のURLを取得:

const nextUri: UriVO = urisToTry.next; 
if (nextUri) 
    connectAgain(nextUri.host, nextUri.port); 
else 
    // you've tried all uris and connection failed. 
+1

素晴らしい!それはありがとう! @Nbooo – KaraEski

+0

こんにちはNbooo、私はあなたのシステムとの素晴らしい作品を追加しますが、私は感謝を助けてください、このシステムのためにもう一つ質問があります!右が は https://stackoverflow.com/questions/45750178/as3-how-to-i-turn-head-of-the-vector-list – KaraEski

+0

こんにちはNboo私の最後の質問のおかげで助けてください。 https://stackoverflow.com/questions/45755573/as3-how-i-add-auto-next-on-list-when-i-click-connect-again-button – KaraEski

関連する問題