Shared object for android crashes, am i using it wrong or is this a error

This works on neko/linux AND android:

    //get the array of names
    var so = SharedObject.getLocal( "names" );
    //try to access the array
    try{
        so.data.names;
    }
    catch(e : Dynamic){//error? the make the array then check
        so.setProperty("names", new Array<String>());
        so.flush();
        try{
            so.data.names;//double check it is fixed
        }
        catch(e : Dynamic){
            trace("Error : " + Std.string(e));//still error please tell me
        }
    }

but if I go after that:
names[0] = “test”;
this crashes on android.

Don’t use try/catch blocks as part of normal code. Especially when compiling to C++, which tends to crash instantly if there’s a null pointer, ignoring any and all catch blocks.

Do this instead:

if(!Reflect.hasField(so.data, "names")) {
     so.data.names = new Array<String>();
     so.flush();
}

Also, when dealing with “nested” structures, “trust, but verify.™” In this case, you need to verify first that the “data” object exists, and, only then that it contains “names.” If you “try to step on one rock to get to the second one,” you might find yourself swimming!

If so is a SharedObject (which it is), it will have a non-null data property. Double-checking would make your code more complicated without any benefit.