I've even added 2 checks for the _nbytes being > 0
and a check for _bytes != null and still it fails with

  1061: Call to a possibly undefined method inflate through
  a reference with static type flash.utils:ByteArray.

(ok, I understand that by "static" compiler means _bytes being null)

My current code:

               private var _nbytes:int = 0;
               private var _bytes:ByteArray = new ByteArray();
               private var _socket:Socket = new Socket();
.....
               // the length of XML-string is prepended as a short (2 bytes)
                private function handleTcpData(event:ProgressEvent):void {
                        trace('handleTcpData: ' + event);
                        while (_socket.bytesAvailable > 0) {
                                if (_nbytes <= 0) {
                                        if (_socket.bytesAvailable < 2) {
                                                trace('Can not read short yet - 
bytesAvailable='+_socket.bytesAvailable);
                                                return;
                                        }
                                        try {
                                                _nbytes = _socket.readShort();
                                                trace('Read _nbytes '+_nbytes);
                                        } catch (e:Error) {
                                                handleTcpError();
                                                return;
                                        }
                                        if (_nbytes <= 0) {
                                                trace('invalid length');
                                                return;
                                        }
                                } else {
                                        if (_socket.bytesAvailable < _nbytes) {
                                                trace('Can not read bytes yet -
bytesAvailable='+_socket.bytesAvailable+' < _nbytes='+_nbytes);
                                                return;
                                        }
                                        try {
                                                _socket.readBytes(_bytes, 0, 
_nbytes);
                                                trace('Read _bytes 
'+_bytes.length);
                                        } catch (e:Error) {
                                                handleTcpError();
                                                return;
                                        }
                                }
                                if (_bytes != null && _bytes.length > 0) {
                                        try {
                                                _bytes.inflate();
                                        } catch (error:IOError) {
                                                trace('inflating failed');
                                                return;
                                        }
                                        trace(_bytes.length);
                                        trace(_bytes);
                                        //updateGUI(_bytes);
                                }
                        }
                }
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to