2009-07-14

Using SharedObject across SWFs

At work we have a web application that is comprised of various SWF files written using Flex 3. Just this past week I was trying to share some data amongst two of those SWFs and was wondering why SWF B could not read the ShareObject created by SWF A.

See normally to read/create a SharedObject you write code like this:

var so:SharedObject = SharedObject.getLocal( "mySO" );

The above line of code will read the SharedObject called mySO or create one if it does not already exist in a similar folder structure as the one that follows (varies based on OS - I am using Vista):

C:\Users\Jimmy\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\blabla\localhost\SWFA\mySO.sol

Since the SharedObject is created in a folder specific to SWF A (see the "\localhost\SWFA" above), SWF B, will not be able to read this SharedObject, thus the both applications cannot share data between eachother.

In order to solve this, you must specify an additional parameter to the getLocal() method call to tell it to save the SharedObject in a folder location accessible by both applications. An example is:

var so:SharedObject = SharedObject.getLocal( "mySO", "/" );

What this will do now is create the SharedObject in the following folder structure:

C:\Users\Jimmy\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\blabla\localhost\mySO.sol

Hope this is helpful to some when working with SharedObjects. It is a simple, yet primitive way to share data amongst two Flex applications without requiring the use of a server of any kind.

16 comments:

elliotr said...

Going to bookmark this one for future reference.

Thanks

Elliot

Ronny said...

Depending on the kind of sharing you could also use a localconnection. Both swf's have to be running at that point though.

Anonymous said...

酒店打工

酒店兼職

台北酒店

打工兼差

酒店工作

酒店經紀

禮服店

酒店兼差

酒店上班

酒店PT

酒店正職

酒店賺錢

酒店日領

Anonymous said...

酒店打工 酒店兼職
台北酒店 打工兼差 酒店工作 禮服酒店
酒店兼差 酒店上班 酒店應徵 酒店 酒店經紀

dayg said...

Just what I need! Thank you very much. :)

lala said...

Thanks for the sharing and if you want to share Outlook data with your colleagues, welcome to check:
WinPST Share Outlook

Arul said...

can i transfer the video object across the swf..?

because localconnection restrict me upto 40kb of data...

Virat said...

Great One Dude

Thanks
Virat

Viagra Online said...

Excellent thanks a lot, I was wondering about this and also still looking for some solution to make my phone works as a modem.

Cialis kaufen said...

Thank you for sharing this information. I totally agree on you with that.

saurabh1403 said...

Can i read the shared object data from an air application which was written by a swf run by flash player in a browser?

Jaro said...

thank you! makes sense!

Cincinnati Neighborhoods said...

WAO I came across to your site and I must say that you have got an amazing site that has attracted a lot of visitors including me.Please keep updating with great posts like this one. I have booked marked your site and am about to email it to a few friends of mine that I know would enjoy reading.

Oliver said...

Awesome, cheers!

Oliver said...

Awesome, cheers!

Oliver said...

Awesome, cheers!