0 Replies Latest reply on Jun 1, 2007 8:07 AM by Rothrock

    AS3 Shared Object Byte Array

    Rothrock Level 5
      So I'm trying to store a compressed ByteArray in a SharedObject. It kind of seems to work, but then I have a problem. When I retrieve the ByteArray from the SharedObject I uncompress it, convert to BitmapData, wrap it in a Bitmap (this is so ridiculous!), and finally add it to the DisplayObject list. Sometimes it works sometimes I got an error saying that the data couldn't be uncompressed.

      After a bit of thought I think I've come to the realization that the ByteArray in the SharedObject is just like any other Array in memory and when I uncompress the "copy" I made the original was also uncompressed. Even though I never ordered a SharedObject.flush() the so must have been written. So that the next time I came back the data in the shared object was already uncompressed.

      Does that seem to make sense?

      So my plan will be to "clone" the data out of the SharedObject. But how to do that? The old Array.slice() trick doesn't work on the ByteArray. Obviously I can just copy every element, but I'm worried that could get slow. Any other tricks?

      Another approach I guess would just be to always recompress the data when I'm done with it so that it remains compressed in the SharedObject. Hmmmm… Anybody got any ideas?

      Here is my code. It is messy because this is all new to me as is AS3 and its structure. If anybody has any good pointers on how to work with SO and storing lots of ByteArrays (and other info) that would be great!