0

我有以下代码。在 onClientClose 方法中,如果它已关闭,我想从 _clientSockets 数组中删除 _socketServicer 实例。如果我不知道它的索引,如何引用数组中的 _socketServicer 实例?

public function connectHandler(event:ServerSocketConnectEvent):void {                            _socketServicer=new SocketService(event.socket, this,log);
            _socketServicer.addEventListener(Event.CLOSE, onClientClose);
            _clientSockets.push(_socketServicer); //maintain a reference to prevent premature garbage collection
        }

        private function onClientClose(event:Event):void {
            //Nullify references to closed sockets
            for each (var servicer:SocketService in _clientSockets) {
                if (servicer.closed)
                    servicer=null;
            }
        }
4

1 回答 1

2

您可以使用.indexOf()

clientSockets[ clientSockets.indexOf(servicer) ];
于 2013-03-06T21:08:35.307 回答