Save (and Load) Bitmap to Local Shared Object

I’m playing with Local Shared Objects, and I was able to save and load simple data types like strings and integers. Pretty cool.

I want to Save/Load a Bitmap Object but I’m having problems. I think I got a Bitmap Object to save but when I loaded it back in, it was basically a blank bitmap. I located the actual .SOL file on my computer and opened it up. It had some basic Bitmap info like scale, rotation, visible, width, height, etc, but NOT the actual bitmap.

So I realized that I need to be saving/loading a BitmapData object instead of just Bitmap. BitmapData holds the actual bitmap pixels, I think. Anyway I saved out a BitmapData object. When i tried to load it back in, I get a type coercion error: “Type Coercion failed: cannot convert Object@df355b1 to flash.display.BitmapData”. I dont get it because this error didnt occur for Strings, ints, or Bitmap Objects. Whats happening?

Also, I looked again at the .SOL file after saving out the BitmapData object, And I dont see any pixel data there. The bitmap I’m saving is 800x800 so the .SOL file should be pretty big but its just a tiny file so I know the pixels havn’t been saved properly.

I need some help please! This is one of those rare occasions where Google just is not helpful.

Here is the code I’m using (Simplified - error handling removed, etc)


// save
var mySo:SharedObject = SharedObject.getLocal("mysharedobjecttest");			
mySo.data.testA = 14;
mySo.data.testB = "hello this is a test";
mySo.data.testC = theBitmapData;
mySo.flush();


// load
var mySo:SharedObject = SharedObject.getLocal("mysharedobjecttest");
trace (int(mySo.data.testA));    // 14
trace (String(mySo.data.testB)); // hello this is a test
theBitmapData = BitmapData(mySo.data.testC);  // ERROR