Advertisement
Guest User

AS3 Tiled loading (Base64 zlib)

a guest
Jan 4th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         private function decompressToVec( data:String ):Vector.<uint>
  2.         {
  3.             // Raw ByteArray from data. Used to decode.
  4.             var ba:ByteArray = Base64.decodeToByteArray( data ); // decoding
  5.             ba.uncompress(); // decompressing
  6.             ba = reverseBA( ba ); // reversing.
  7.            
  8.             return baToVector( ba ).reverse(); // to vector and reversing again.
  9.         }
  10.        
  11.         private function baToVector( ba:ByteArray ):Vector.<uint>
  12.         {
  13.             var endVec:Vector.<uint> = new Vector.<uint>( ba.length / 4 );
  14.             ba.position = 0;
  15.             for ( var i:int = 0; i < ba.length / 4; i++ )
  16.             {
  17.                 endVec[ i ] = ba.readUnsignedInt();
  18.             }
  19.             return endVec;
  20.         }
  21.        
  22.         private function reverseBA( ba:ByteArray ):ByteArray
  23.         {
  24.             var endBA:ByteArray = new ByteArray();
  25.             ba.position = ba.length;
  26.             for ( var i:int = 0; i < ba.length; i++ )
  27.             {
  28.                 ba.position--;
  29.                 endBA.writeByte( ba.readByte() );
  30.                 ba.position--;
  31.             }
  32.             return endBA;
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement