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

2010-10-03 Thread Alexander Farber
Hello,

I'm trying to compress XML data being exchanged via Socket with a Perl
backend and after taking several hurdles, I'm stuck at this error message:

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

My code is:

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();
}
} 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();
}
}
try {
_bytes.inflate();  // this fails for 
some reason?
} catch (error:IOError) {
trace('inflating failed');
}
trace(_bytes.length);
trace(_bytes);
//updateGUI(_bytes);
}
}

Can anyone please spot an error in the code above?

I've started preparing a simple test case, but the following just works:

import flash.utils.*;

var _bytes:ByteArray = new ByteArray();
_bytes.writeUTFBytes('Hello world');
trace('before: ' + _bytes);
try {
_bytes.deflate();
_bytes.inflate();
} catch (e:Error) {
trace(e);
}
trace('after: ' + _bytes);

Thank you for any hints
Alex
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Dave Watts
 I'm trying to compress XML data being exchanged via Socket with a Perl
 backend and after taking several hurdles, I'm stuck at this error message:

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

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.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Alexander Farber
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


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Alexander Farber
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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Henrik Andersson

Dave Watts skriver:

I'm trying to compress XML data being exchanged via Socket with a Perl
backend and after taking several hurdles, I'm stuck at this error message:

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


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.



So what? That is no grounds for throwing a compiler error. It's your job 
to ensure that stuff is setup properly at runtime.


A runtime issue will never raise a compiler time error.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Alexander Farber
On Sun, Oct 3, 2010 at 7:44 PM, Henrik Andersson he...@henke37.cjb.net wrote:
 Dave Watts skriver:
 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.


 So what? That is no grounds for throwing a compiler error. It's your job to
 ensure that stuff is setup properly at runtime.

 A runtime issue will never raise a compiler time error.

No, I think Dave has a valid point - if my ByteArray _bytes
is null - because a socket read has thrown an exception,
then the compiler might be able to recognize it (same is in Java).

But now I have added return's everywhere and
strangely it still doesn't compile.

I've searched my code for all occurences of _bytes and _nbytes too...

Regards
Alex
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Tom Gooding
It looks to me like your compiler error is due to a call to _bytes.inflate() 
where the compiler detects that inflate() is not a method of the ByteArray 
class, I think it was added in later player versions - check your publish 
settings?

older docs (missing): 
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html
newer docs (present): 
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/utils/ByteArray.html

HTH 

Tom


On 3 Oct 2010, at 18:44, Henrik Andersson wrote:

Dave Watts skriver:
 I'm trying to compress XML data being exchanged via Socket with a Perl
 backend and after taking several hurdles, I'm stuck at this error message:
 
1061: Call to a possibly undefined method inflate through
a reference with static type flash.utils:ByteArray.
 
 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.
 

So what? That is no grounds for throwing a compiler error. It's your job to 
ensure that stuff is setup properly at runtime.

A runtime issue will never raise a compiler time error.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Alexander Farber
Bingo, Tom -

On Sun, Oct 3, 2010 at 8:14 PM, Tom Gooding t...@quickthinkmedia.co.uk wrote:
 It looks to me like your compiler error is due to a call to _bytes.inflate() 
 where the compiler detects that inflate() is not a method of the ByteArray 
 class, I think it was added in later player versions - check your publish 
 settings?

 older docs (missing): 
 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html
 newer docs (present): 
 http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/utils/ByteArray.html

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

I was publishing for Player 9! After I've changed
it to Player 10, the code has compiled. Thank you

If I want to publish for Player 9, then I probably have to modify
my backend to use zlib and then call _bytes.uncompress()?

Regards
Alex

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Henrik Andersson

Alexander Farber skriver:

On Sun, Oct 3, 2010 at 7:44 PM, Henrik Anderssonhe...@henke37.cjb.net  wrote:

Dave Watts skriver:

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.



So what? That is no grounds for throwing a compiler error. It's your job to
ensure that stuff is setup properly at runtime.

A runtime issue will never raise a compiler time error.


No, I think Dave has a valid point - if my ByteArray _bytes
is null - because a socket read has thrown an exception,
then the compiler might be able to recognize it (same is in Java).


The compiler does not know that an exception has been thrown. That's 
runtime events. Exceptions are not checked in actionscript, so the 
compiler MAY NOT raise any errors.



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Call to a possibly undefined method inflate through a reference with static type flash.utils:ByteArray

2010-10-03 Thread Dave Watts
 No, I think Dave has a valid point - if my ByteArray _bytes
 is null - because a socket read has thrown an exception,
 then the compiler might be able to recognize it (same is in Java).

 The compiler does not know that an exception has been thrown. That's runtime
 events. Exceptions are not checked in actionscript, so the compiler MAY NOT
 raise any errors.

In general, I think Henrik is more likely to be correct about
Actionscript than I am. I've been doing a lot of Java programming
lately, where you do have checked exceptions, but I'm off the mark
here.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders