AS3:将数组存储在共享库中 [英] AS3: Store array in shared object

查看:117
本文介绍了AS3:将数组存储在共享库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了这个问题很长时间了,但似乎找不到确切的答案.基本上,我想做的是获取一个数组并将其存储在共享对象中,然后读取存储在对象中的内容,并在脚本启动时将其放回数组列表中(希望这很有意义).

此刻,我被认为共享对象只能存储多个变量,因此我不确定如何将数组添加到其中.

数组本身的声明如下所示:

var lvl1highScores:Array = new Array();

用户每次在各个级别获得高分时都可以将其添加进来:

    lvl1highScores.push({score:int(vinylCollected) , player:String(highScoreInput.text)});
lvl1highScores.sortOn("score", Array.DESCENDING | Array.NUMERIC);

我希望这对某人有足够的帮助.如果我无法将整个数组存储在共享对象中,还有其他方法可以存储此信息吗?

欢呼

解决方案

您应该能够做到这一点,

要写入共享对象

//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();

要在其他地方重新阅读

//get the mySharedObject back
var so:SharedObject = SharedObject.getLocal("mySharedObject");
//get your array back
myArray = so.data.storedArray;

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

解决方案

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;

这篇关于AS3:将数组存储在共享库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆