On Sun, Oct 3, 2010 at 6:27 PM, Dave Watts <dwa...@figleaf.com> wrote:
> In your code, if there's nothing to read, your exception handlers fall
> through after calling handleTcpError. At compile time, the compiler
> has no guarantee that there'll be anything in the byte array.
>

Thanks Dave, you're correct with the fall-through.
I've added "return| statements in the catch branches there.
However the compile-time error still persists:

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

I wonder why does compiler think, that _bytes is static?

Also if I remove the _bytes.inflate(), then the socket I/O works
ok, I can see the same amount of (deflated) bytes being read
as I send from my backend.

                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;
                                        }
                                } 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;
                                        }
                                }
                                try {
                                        _bytes.inflate();  // this fails
                                } catch (error:IOError) {
                                        trace('inflating failed');
                                }
                                trace(_bytes.length);
                                trace(_bytes);
                                //updateGUI(_bytes);
                        }
                }
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to