Copy link to clipboard
Copied
Hi guys...
Is there anyway to save a var value forever?
Like... let´s say I have this:
private var b:int;
private var xb:int;
public function UPD()
{
start()
}
private function start():void
{
//add a button to do something
//add a button to do whatever
}
//define the listener for the buttons (MouseEvent.CLICK, something & MouseEvent.CLICK, whatever)
private function something(e:MouseEvent):void
{
if (!b){b = (1 + xb);}
//another function to do something else after adding b + xb
}
private function whatever(e:MouseEvent):void
{
xb++
}
This way xb (and b) will have 1 more each time I click on the whatever button...now let´s say I close everything...how can I have the values I had before, back, when I open it again, so xb doesn´t start from 0 again, but it keeps the clicks from previous time?
Thanks a lot!!!
You need to incorporate some means of external storage for the values such that you can retrieve them when you come back to the program after having closed and reopened it. This could take the form of storing the data in a database (MySQL), or a data file (text/xml), or as a SharedObject (Flash version of a cookie).
Copy link to clipboard
Copied
You need to incorporate some means of external storage for the values such that you can retrieve them when you come back to the program after having closed and reopened it. This could take the form of storing the data in a database (MySQL), or a data file (text/xml), or as a SharedObject (Flash version of a cookie).
Copy link to clipboard
Copied
Hey Ned, thanks for your answer...
I was thinking of using a SO... Let me add another question to this topic: Can I have two different instances of a SO in the same program?
(I am using one, already, for a local highscore table)
Thanks!
Copy link to clipboard
Copied
Yes, you can create different SO's as needed... just be sure to name them differently if they need to be separate but simultaneously available.
Copy link to clipboard
Copied
Great!!!!. Thanks a lot!!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now