0

I have an application that is loading an swf. I can use that swf several times until there is a new one on the server. Therefore, I want to save as a SharedObject the loader containing the swf. Next time I could use the loader from the SharedObject instead of having to load the swf again (since it was already loaded one time).

For that I do the following:

var sObject: SharedObject = SharedObject.getLocal('PrefsObj');//my SharedObject.
registerClassAlias( "remoteSharedObject.NxLoader", NxLoader );//I register every time my custom Loader class which just extends from Loader.

if(sObject && sObject.data &&  sObject.data.loader)//I check if the sharedObject is empty? If not I get the previously saved loader.
  loader = sObject.data.loader as NxLoader;
else//if it's empty I create the loader and load the bytes
{
  loader = new NxLoader();
  loader.loadBytes(swfBA,context);
}     
this.addChild(loader);//add the loader.
sObject.data.loader = loader;//save the loader on my sharedObject for next time.
sObject.flush();//done.

What am I doing wrong? The loader inside the SharedObject is not recognized and comes as an Object. When it reaches the addChild method - Boom! -> Main Thread (Suspended: TypeError: Error #2007: Parameter child must be non-null.)

Thanks

ketan
  • 19,129
  • 42
  • 60
  • 98
Dave
  • 598
  • 2
  • 4
  • 17
  • Might want to expound on what *is* happening with the current code, and how that deviates from what you expected. – Atriace Nov 05 '13 at 16:59
  • I mention that the Loader inside the SharedObject is not recognized and comes as an Object. I though that would be clear enough. What I mean by that is that in the SharedObject there should be a NxLoader object and not a simple Object. That is why I use the registerClassAlias. Also the NxLoader class uses [RemoteClass(alias="remoteSharedObject.Loader")] – Dave Nov 06 '13 at 10:25

1 Answers1

1

I see; so you want to cache your SWFs on the local system to reduce server overhead. According to Adobe's Reference...

"The SharedObject class is used to read and store limited amounts of data on a user's computer ...

... sometimes SWF files may not be allowed to write local shared objects, and sometimes the data stored in local shared objects can be deleted without your knowledge."

If you look at the user default settings for SharedObject storage, you notice a 100KB maximum on data stored there. Saving an entire SWF is therefore impractical (if not impossible) as most files are greater than this maximum. This makes sense as to why you'd receive a null value from your saved object.

Community
  • 1
  • 1
Atriace
  • 2,572
  • 1
  • 14
  • 27
  • Yeah I had totally forgot about that. That pretty much explains it, 100K is defenitely to small. – Dave Nov 07 '13 at 08:12
  • And do you know how to programatically change that maximum to unlimited. – Dave Nov 07 '13 at 08:37
  • You can't. That would break the security sandbox. However, you could prompt the user to increase their storage, and then make the window appear. – Atriace Nov 07 '13 at 12:49