Actionscript 3 saving currentframe location to loc

2020-05-01 08:06发布

问题:

I asked similar question sometime ago, but I am making new one to be much more specific with my question with some example!

I´ve found this code snippet/tutorial from googling, but I cant seem to figure out how to modify it for my needs:

// open a local shared object called "myStuff", if there is no such object - create a new one
var savedstuff:SharedObject = SharedObject.getLocal("myStuff");
// manage buttons
btnSave.addEventListener(MouseEvent.CLICK, SaveData);
btnLoad.addEventListener(MouseEvent.CLICK, LoadData);

function SaveData(MouseEvent){
 savedstuff.data.username = nameField.text // changes var username in sharedobject
 savedstuff.flush(); // saves data on hard drive
 }
function LoadData(MouseEvent){
 if(savedstuff.size>0){ // checks if there is something saved
 nameField.text = savedstuff.data.username} // change field text to username variable
 }

// if something was saved before, show it on start
if(savedstuff.size>0){
nameField.text = savedstuff.data.username}

So what I am trying to figure out how to do, is to save users current frame to local hard drive, as my flash progress is based on frame location. yeah, so how do I modify it so that it stores data of current frame? and how about current frame inside movieclip, if that is makes things different?

help MUUUCH appreciated! thanks!

回答1:

In your example it looks like it is already saving something to the shared object:

savedstuff.data.username = nameField.text;

Just replace it with the movie clip frame value instead (and probably under a different property name other then "username").

Then on load, there is another line where it loads the data:

nameField.text = savedstuff.data.username;

It would be the same way, except replace "username" with whatever property name you choose. Then you may have to parse into an int again and use it to restore progress however way you have it set up.