AS3如何转动矢量列表的头部? [英] AS3 How to i turn head of the Vector list?
本文介绍了AS3如何转动矢量列表的头部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是什么时候完成我的列表如何我打开列表头?
这是我目前的代码
public class UriIterator
{
private var _availableAddresses:Vector。< SocketConnection> = new Vector。< SocketConnection>();
$ b public function UriIterator()
{
}
公共函数withAddress(host:String ,port:int):UriIterator {
const a:SocketConnection = new SocketConnection(host,port);
_availableAddresses.push(a);
返回这个;
}
public function get next():SocketConnection {
return _availableAddresses.length? _availableAddresses.pop():null;
code
谢谢
public class UriIterator
{
private var _currentIndex:int = 0;
private var _availableAddresses:Vector。< SocketConnection> = new Vector。< SocketConnection>();
$ b $ public function withAddress(host:String,port:int):UriIterator {
const a:SocketConnection = new SocketConnection(host,port);
_availableAddresses.push(a);
返回这个;
public function get first():SocketConnection {
_currentIndex = 0;
if(_currentIndex> = _availableAddresses.length)
return null;
return _availableAddresses [_currentIndex ++];
}
public function get next():SocketConnection {
if(_currentIndex> = _availableAddresses.length)
return null;
return _availableAddresses [_currentIndex ++];
现在得到第一个条目, $ c> const firstConn:SocketConnection = iterator.first
并获取其余的,只要继续调用 iterator.next
即可。
I have a Vector for ip and port list and socket connection, When connection lose i click button and call the next ip and port from vector list.
My question is when finish my list how to i turn head of the list ?
This my current code
public class UriIterator
{
private var _availableAddresses: Vector.<SocketConnection> = new Vector.<SocketConnection>();
public function UriIterator()
{
}
public function withAddress(host: String, port: int): UriIterator {
const a: SocketConnection = new SocketConnection(host, port);
_availableAddresses.push(a);
return this;
}
public function get next(): SocketConnection{
return _availableAddresses.length ? _availableAddresses.pop() : null;
}
}
Thanks
解决方案 In current implementation you can traverse the list only once. You need to change the code to keep the list unmodified:
public class UriIterator
{
private var _currentIndex:int = 0;
private var _availableAddresses: Vector.<SocketConnection> = new Vector.<SocketConnection>();
public function withAddress(host: String, port: int): UriIterator {
const a: SocketConnection = new SocketConnection(host, port);
_availableAddresses.push(a);
return this;
}
public function get first():SocketConnection {
_currentIndex = 0;
if (_currentIndex >= _availableAddresses.length)
return null;
return _availableAddresses[_currentIndex++];
}
public function get next(): SocketConnection {
if (_currentIndex >= _availableAddresses.length)
return null;
return _availableAddresses[_currentIndex++];
}
}
Now to get the first entry you call const firstConn:SocketConnection = iterator.first
and to get the rest of them, just keep calling iterator.next
.
这篇关于AS3如何转动矢量列表的头部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文