Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Saving a value in a var forever?

Explorer ,
Oct 04, 2013 Oct 04, 2013

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!!!

TOPICS
ActionScript
952
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 05, 2013 Oct 05, 2013

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).

Translate
LEGEND ,
Oct 05, 2013 Oct 05, 2013

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 05, 2013 Oct 05, 2013

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 05, 2013 Oct 05, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 05, 2013 Oct 05, 2013
LATEST

Great!!!!. Thanks a lot!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines