all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

SharedObject and Array [AS-1]


SharedObject and Array [AS-1] norby77
4/27/2005 12:00:00 AM
flash actionscript: Hi all,

I've experience a strange problem with MX2004 - AS 1 - player 6.

In my application I've defined some arrays.

_root.myarray1 = new Array ()
_root.myarray1[17] = -1
_root.myarray1[16] = -1

I save it in a local SOL.

Cookies = sharedobject.getlocal("game");
Cookies.data.myarray1 = _rootmyarray1;

Unfortunately, if I test the movie, Flash crash.
In fact I've checked that if I've invert the order assigning value to
position, everythings goes well.

_root.myarray1 = new Array ()
_root.myarray1[16] = -1
_root.myarray1[17] = -1

Seeing in the SOL with .SOL Editor, I've noticed tha arrya is saved in the
definition order (position 17 before 16).
If I change the definition order, everything goes well. If I trace the array
before saving, it's same in both cases.

Also trying to open the SOL with Sephiroth Sol reader, doesn't succed.

Have anyone have experienced the problem? Suggestions?
My problem isn't the start definition (I can change the order), but the
application is a game, and the array is used to save resource collected (not
always in the same order).

Thanks,
Norby
Re: SharedObject and Array [AS-1] Flashkernel
4/27/2005 12:00:00 AM
_root.myarray1 = new Array ()
_root.myarray1[17] = -1
_root.myarray1[16] = -1

Re: SharedObject and Array [AS-1] norby77
4/27/2005 12:00:00 AM
Thank you.
I tried :
_root.myarray1 = new Array (20)
_root.myarray1[17] = -1
_root.myarray1[16] = -1

But this doesn't solve the problem... ;-(

Bye,
Re: SharedObject and Array [AS-1] tralfaz
4/27/2005 7:50:08 PM
[quoted text, click to view]

Norby, it's probably not anything to do with the crash, but make sure
you use semicolons at the end of each statement.
Being on a different line doesn't make it a new statement. (maybe you
are already doing it)
tralfaz

Re: SharedObject and Array [AS-1] Flashkernel
4/28/2005 12:00:00 AM
The problem lies here
Cookies = sharedobject.getlocal("game");
Cookies.data.myarray1 = _rootmyarray1;/// it should be _root.myarray1 missing dot

Re: SharedObject and Array [AS-1] norby77
4/28/2005 12:00:00 AM
tralfaz, Flashkernel
thanks a lot for the advices.

Unfortunately they doesn't solve.
I've inserted the semicolons, but anything canges.
The missing dot is my fault in posting the code, I'm sorry.

To clarify, my code works: the SOL it's generated and the values stored.
The problem is the structure of the SOL, the array position are stored in the
assignement order, causing malfunction.
I don't know the SOL specification, so I can't say if it's a problem in
writing (array position has to be in order) or reading the SOL (the order isn't
imperative, but the player crash in reading it).

Thanks a lot,
Norby
Re: SharedObject and Array [AS-1] norby77
4/28/2005 12:00:00 AM
tralfaz,

thanks a lot.
Your advice it's anyway useful.
I've done "copy & paste", only changed variable name (to make code more
readable).
In fact I'm publishing in Player 6, AS 1 cause some code used it was developed
in MX, and can be very difficult to check all syntax (not only case sensitive,
but also variable declaration).

Anyway, I've make a small .fla to test only this problem and isolate it.
This is the code:

Frame 1 actions
_root.myarray1 = new Array ();
_root.myarray1[17] = -1;
_root.myarray1[16] = -1;

Frame 2 acrions
Cookies = SharedObject.getLocal("test");
Cookies.data.myarray1 = _root.myarray1;
Trace ("_root.myarray1"+_root.myarray1)
Trace ("Cookies.data.myarray1"+Cookies.data.myarray1)
trace("saved the cookies")
Cookies.flush();


I hope in this way can be more simple to understand my problem.
Re: SharedObject and Array [AS-1] tralfaz
4/28/2005 1:03:44 AM
[quoted text, click to view]

norby.. probably more useless advice but with MX2004 it is case
sensitive so should be SharedObject with the capitol letters (as
pointed out by another poster recently). Shouldn't make it crash
though and you say it is writing the SOL file. I would recommend
using copy/paste when posting your code instead of typing it in just
so that typos aren't brought up.
tralfaz

AddThis Social Bookmark Button