2

how to change sharedObject save location,I want to save shared object on server for particular user, what I do for this?

Devendra
  • 1,864
  • 6
  • 29
  • 49

2 Answers2

0

You can look at SharedObject.getRemote() if you have a Flash Media server. Alternatively you can encode the data associated with your SharedObject as JSON and store it in a database.

Marty
  • 39,033
  • 19
  • 93
  • 162
  • thanks mr.marty,but My sharedobject contains image and similar types data. so will it be able to encode in JSON? – Devendra Feb 25 '13 at 07:48
  • @dev Depends how you're linking the image to the SharedObject. Do you mean that you're assigning a Bitmap to the data? – Marty Feb 25 '13 at 07:50
  • @dev You can convert the image into data that can be stored. [See here for an example](http://stackoverflow.com/questions/3349019/as3-bitmapdata-to-bytearray). Still I would probably try find alternate ways of doing this. – Marty Feb 25 '13 at 08:02
  • so if i save image in bytearray.. will JSON file strore this data? I think JSON file store strings more accurately ... – Devendra Feb 25 '13 at 08:07
  • What @MartyWallace suggests is that you should not use a SharedObject or an LSO to store an image or large data. Look for alternatives like a db or filesystem by encoding it. – Mohammad Haseeb Feb 25 '13 at 17:05
0

Bad way, but it works

var src:ByteArray = your byteArray;

var arr:Array = new Array();
for (var i:int = 0; i < src.length; i++)
{
    arr.push(src.readByte());
}
var jsonStr:String = arr.join("|");

and conversely...

var retArr:Array = jsonStr.split("|");
var ba:ByteArray = new ByteArray();
for (var j:int = 0; j < retArr.length; j++)
{
    ba.writeByte(retArr[j]);
}

var ldr:Loader = new Loader();
ldr.loadBytes(ba);
addChild(ldr);
Smolniy
  • 456
  • 3
  • 9