I have searched for an answer to this question for quite a while but can't seem to find a definite one. Basically what I am trying to do is take an Array and store it within a shared object, and then read what is stored in the object and put it back into an array list when the script is started (hope this makes sense).
我已经搜索了这个问题的答案了很长一段时间,但似乎找不到明确的答案。基本上我要做的是获取一个数组并将其存储在一个共享对象中,然后读取存储在该对象中的内容,并在脚本启动时将其放回到数组列表中(希望这是有意义的)。
At the moment I am led to believe that shared objects can only store multiple variables, so I am not sure how I would go about adding an array to one.
目前我被认为共享对象只能存储多个变量,所以我不确定如何将数组添加到一个变量中。
The array itself is declared as shown here:
数组本身声明如下:
var lvl1highScores:Array = new Array();
And it can be added to by the user every time they reach a high score in each level as so:
用户每次在每个级别达到高分时都可以添加它,如下所示:
lvl1highScores.push({score:int(vinylCollected) , player:String(highScoreInput.text)});
lvl1highScores.sortOn("score", Array.DESCENDING | Array.NUMERIC);
I hope this is enough information for someone to help out. If I am unable to store the whole array in a shared object, is there any other way of storing this information?
我希望这是有足够信息帮助别人的。如果我无法将整个数组存储在共享对象中,是否还有其他存储此信息的方法?
Cheers
2 个解决方案
#1
2
You should be able to do this,
你应该能够做到这一点,
To write to a shared object
写入共享对象
//returns the mySharedObject if it exists, if not creates a new one
var so:SharedObject = SharedObject.getLocal("mySharedObject");
//take your array and put it on the so
so.data.storedArray = myArray;
//save the data
so.flush();
To read it back elsewhere
在其他地方读回来
//get the mySharedObject back
var so:SharedObject = SharedObject.getLocal("mySharedObject");
//get your array back
myArray = so.data.storedArray;
#2
2
I found something helpful that I'm going to add into the above code answer:
我发现了一些有用的内容,我将在上面的代码中添加:
To read it back elsewhere
//get the mySharedObject back
var so:SharedObject = SharedObject.getLocal("mySharedObject","/");
//get your array back
myArray = so.data.storedArray;
To avoid inadvertently restricting access to a shared object, use the localpath parameter. - which is the "/"
要避免无意中限制对共享对象的访问,请使用localpath参数。 - 哪一个是 ”/”
#1
2
You should be able to do this,
你应该能够做到这一点,
To write to a shared object
写入共享对象
//returns the mySharedObject if it exists, if not creates a new one
var so:SharedObject = SharedObject.getLocal("mySharedObject");
//take your array and put it on the so
so.data.storedArray = myArray;
//save the data
so.flush();
To read it back elsewhere
在其他地方读回来
//get the mySharedObject back
var so:SharedObject = SharedObject.getLocal("mySharedObject");
//get your array back
myArray = so.data.storedArray;
#2
2
I found something helpful that I'm going to add into the above code answer:
我发现了一些有用的内容,我将在上面的代码中添加:
To read it back elsewhere
//get the mySharedObject back
var so:SharedObject = SharedObject.getLocal("mySharedObject","/");
//get your array back
myArray = so.data.storedArray;
To avoid inadvertently restricting access to a shared object, use the localpath parameter. - which is the "/"
要避免无意中限制对共享对象的访问,请使用localpath参数。 - 哪一个是 ”/”