SharedObject#size reports different values Flash vs HTML5


#1

Hi. I’ve been doing some tests with SharedObject#size and it seems that for an newly created SharedObject instance, size reports different values in Flash and HTML5.

The relevant code is:

var so = SharedObject.getLocal("SharedObjectTest");
trace(so.size);

In Flash, it prints 0. In HTML5, it prints 2.

Back in the old Flash days, I’ve used (and seen used) checks like (so.size == 0) for simple detection of a new user of the application.

Thanks for looking into this.


#2

You can check the existence of so.data so you don’t have to rely on size


#3

no, it doesn’t work, so.data is never null. you can check in openfl.net, SharedObject.hx the implementation of SharedObject#getLocal does this:

sharedObject.data = {};

#4

but anything you put in data is null. come on now :smiley:


#5

settings = so.data.settings;
if ( settings == null ) {
//voila
}


#6

sure, that works or, if you store directly in data atomic types:

someField = Reflect.hasField(so.data, "someFieldName") ? so.data.someFieldName : aDefaultAtomicValue;

was just trying to point out a possible back compatibility issue.


#7

thanks, sounds like this is something we should improve:

Perhaps we could hard-code a -2 in there (if we are bold) or do a null check, I agree we should return 0 as expected