Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For small amounts of data, you're best-off just going with automaticoo's solution by using SharedObjects.. they take minimal time to set up and are an efficient way of storing small amounts of data.</p> <p>However, if it's not for you, you could always load/save to a text file. You can do this using ByteArrays and FileReferences.</p> <p>Since you brought up saving to a word file, I would suggest saving to a text file would be the best way of achieving your goal (although other than your word doc. suggestion, i'm not sure.. your aim is sort of unclear)</p> <p>Here is a seriously quick demonstration of saving to a text file.. If you need help loading it too, let me know.</p> <pre><code>function savedata() { var bytes:ByteArray = new ByteArray(); var fileRef:FileReference = new FileReference(); bytes.writeMultiByte(playername + "\n", "iso-8859-1"); bytes.writeMultiByte(playerscore.toString(),"iso-8859-1"); fileRef.save(bytes,"savedata.txt"); } </code></pre> <p>This is pretty simply.. By using writeMultiByte, we can write as much data as needed before saving our text file! This is especially useful if you have arrays of data you need to save.</p> <p>Anyway, the "iso-8859-1" is simply a reference to the character set / file-format being used.. I'm not sure if you can simply write utf-16 etc. instead.. I've always just used it as it is written above.</p> <p>The result in the text file here will be the following:</p> <p>Peter</p> <p>9547 (but up one line)</p> <p>To load, you can just split data by line, resulting in an array full of strings and ints/numbers (however your scores may work). Again, let me know if you need help doing that.</p> <p>I'm not sure if this is the most efficient method of achieving what you're after since your goal isn't entirely clear to me, but it has been a very useful way for myself in storing large amounts of data, which I'm guessing you are wanting to do if you are compounding all the scores of players.</p> <p>edit:</p> <p><strong>Okay, to the questions you posed below:</strong></p> <ol> <li>To save more than one user's score is simple. Simply have a single array which loads the data from the text file (if the text file exists), then adds the new score to the end of the array, then saves back to the text file.</li> </ol> <p>Here is an example:</p> <pre><code>var dataloader:URLLoader = new URLLoader(); var dataarray:Array = new Array(); // do this where you intialise other vars function preparesave() { dataloader.load(new URLRequest("savedata.txt")); } dataloader.addEventListener(Event.COMPLETE,savedata); function savedata (event:Event) { dataarray = event.target.data.split(/\n/); dataarray.push(playername); dataarray.push(playerscore); var bytes:ByteArray = new ByteArray(); var fileRef:FileReference = new FileReference(); for (var i = 0; i &lt; dataarray.length;i++) { bytes.writeMultiByte(dataarray[i] + "\n", "iso-8859-1"); } fileRef.save(bytes,"savedata.txt") } </code></pre> <p>What this does is take any existing save data, pushes it to an array (where one line on your save file is one array data entry), adds your appropriate data, and pushes it back out to the save file.</p> <p>(2) To load this in whilst in the main menu, simply place this code in the frame of the main menu..</p> <pre><code>dataloader.load(new URLRequest("savedata.txt")); dataloader.addEventListener(Event.COMPLETE,loaddata); function loaddata (event:Event) { dataarray = event.target.data.split(/\n/); } </code></pre> <p>This will load all your existing data into an array. What you do from then on is up to you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload