I think uncompress() works on an entire ByteArray. Here's the starting
code for reading a SWF that I use. It copies the compressed part of the
SWF ByteArray into a separate ByteArray, uncompresses it, and copies it
back.
 
- Gordon
 
private function read():void
 {
  version = data.readUnsignedInt();
  if (version != SWC9 && version != SWF9)
   throw new Error("unsupported version");
   
  length = data.readUnsignedInt();
  size = length;
  
  if (version == SWC9)
  {
   // Uncompress the rest of the SWF
   // before continuing to read.
   var byteArray:ByteArray = new ByteArray();
   byteArray.endian = "littleEndian";
   var pos:int = data.position;
   data.readBytes(byteArray, 0, data.length - data.position);
   byteArray.uncompress();
   data.length = pos;
   data.writeBytes(byteArray, 0, byteArray.length);
   data.position = pos;
  }
  
  bounds = readRect();
  frameRate = data.readUnsignedByte() << 8 | data.readUnsignedByte();
  frameCount = data.readUnsignedShort();
  
  readTags();
  
  if (data.length != length || data.position != data.length)
   throw new Error();
 }


________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Samuel R. Neff
Sent: Friday, November 09, 2007 3:42 PM
To: [email protected]
Subject: RE: [flexcoders] classes in packages



The docs for uncompress() are not clear how it deals with the position
of the byte array.  The docs are better in Flex 3 than Flex 2 but the
new addition seems to indicate it tries to decompress the entire byte
array which would cause failure in the case of a SWF since the first two
headers for SWF are uncompressed and the rest of the SWF is compressed
(i.e., can ByteArray.uncompress() handle data that is partially raw and
partially compressed?)
 
This is the part that gives me pause:
 
"
After the call, the length property of the ByteArray is set to the new
length. The position property is set to 0.
"
 
Is it correct to set position back to 0 if position was not 0 to start
with?
 
Sam
 

-------------------------------------------
We're Hiring! Seeking a passionate developer to join our team building
Flex based products. Position is in the Washington D.C. metro area. If
interested contact [EMAIL PROTECTED]
  

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Gordon Smith
Sent: Friday, November 09, 2007 5:31 PM
To: [email protected]
Subject: RE: [flexcoders] classes in packages


> is it even possible to parse SWF in AS3 given that SWF is compressed
format and not byte aligned?
 
Yes, it's possible. You can use the uncompress() method of the ByteArray
class to uncompress the compressed part. You don't have to write a
decompressor, but you do have to write a bit-by-bit reader.
 
- Gordon

 

Reply via email to