5

Is it possible to store a Image in a SharedObject in Flash? It would be nice if it would work. I need to "store" Images locally but it seems not to be supported by Flash... So I 'ld like to put those images in a SharedObject that can be saved... but does it work with images?

I tried it with a Bitmap but if I want to read and add it to the stage it says that the Object can't be converted to a Bitmap...

var image:Bitmap = //some awesome image;

sharedObject = SharedObject.getLocal("img");
sharedObject.data.img = image;
sharedObject.flush();

Error here ->

sharedObject = SharedObject.getLocal("img");
addChild(Bitmap(sharedObject.data.img));
Jacob Poul Richardt
  • 3,145
  • 1
  • 26
  • 29
Hank
  • 65
  • 1
  • 4
  • Is saving the file in JPG or PNG format out of the question? Is this data supposed to be out of sight, out of mind? If you're using flash player 10, the flash.net.FileReference class can help you. Using the save() method when ready to write the ByteArray of your bitmapData to disk will allow you to save a copy to your disk. – Brian Hodge Sep 28 '09 at 17:36

3 Answers3

10

In this case, you need to write your Bitmap to a ByteArray (in other words - binary data) before you set your shared object. Then you need to read it from a ByteArray into a bitmap when you retrieve it. Here is a quick sample the hopefully will get you moving in the right direction:

http://www.kirupa.com/forum/showthread.php?t=306972

David Tucker
  • 146
  • 1
  • 2
  • it's also worth nothing that you don't actually have to encode to jpeg for this to work, as you can create a ByteArray with BitmapData.getPixels()... although i haven't been able to make it work 100% it should be theoretically possible – Daniel Jun 02 '10 at 22:44
3

Don`t forget, shared object has limited size (100Kb default)

peko
  • 497
  • 2
  • 9
  • It also creates what I'd call a horrible experience for the user, with the confusing Flash Player dialog that pops up asking for permission to increase the local storage. – Joel Hooks Sep 28 '09 at 15:37
  • Its not true that it has a limit of 100kb. It has a default limit of 100kb which can be increased through the aforementioned confusing pop up. – Tom Jul 20 '11 at 00:46
1

Images to/from SharedObject.data - easy, free and ready to use class which includes full SharedObject events and status logic: Images to/from SharedObject.data

iFlash
  • 11
  • 1