How do I save a dynamic text?











up vote
0
down vote

favorite












I have a dynamic text field that changes from 100 to 0 and vice versa when a button is clicked. I want this number to be saved when exiting the application, but it seems that it's not returning the last clicked value when the application reopens. This is the code, any help please?



import flash.events.MouseEvent;
import flash.media.SoundChannel;
import flash.ui.Mouse;

var saveDataObject:SharedObject;
var currentScore:Number;
options_mc.sound_btn.addEventListener(MouseEvent.CLICK, mute);

options_mc.test3.addEventListener(MouseEvent.CLICK, test3);
init();
function mute(event:MouseEvent)
{

if(currentScore == 100)
{
currentScore = 0
options_mc.onoff_txt.text = String(currentScore);

}
else if(currentScore == 0)
{
currentScore = 100
options_mc.onoff_txt.text = String(currentScore);
}
saveData();
}
function init():void
{

saveDataObject = SharedObject.getLocal("test");
currentScore = 100;




if (saveDataObject.data.savedScore == null)
{
trace("No saved data yet.");
saveDataObject.data.savedScore = currentScore;
}
else
{
trace("Save data found.");
loadData();
}


}

function saveData():void
{
saveDataObject.data.savedScore = currentScore;
trace("Data Saved!");
saveDataObject.flush();
trace(saveDataObject.size);
}

function loadData():void
{
if(currentScore == 100)
{
currentScore = saveDataObject.data.savedScore;
trace("Data Loaded!");
}
else if(currentScore == 0)
{

currentScore = saveDataObject.data.savedScore;
}
}









share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a dynamic text field that changes from 100 to 0 and vice versa when a button is clicked. I want this number to be saved when exiting the application, but it seems that it's not returning the last clicked value when the application reopens. This is the code, any help please?



    import flash.events.MouseEvent;
    import flash.media.SoundChannel;
    import flash.ui.Mouse;

    var saveDataObject:SharedObject;
    var currentScore:Number;
    options_mc.sound_btn.addEventListener(MouseEvent.CLICK, mute);

    options_mc.test3.addEventListener(MouseEvent.CLICK, test3);
    init();
    function mute(event:MouseEvent)
    {

    if(currentScore == 100)
    {
    currentScore = 0
    options_mc.onoff_txt.text = String(currentScore);

    }
    else if(currentScore == 0)
    {
    currentScore = 100
    options_mc.onoff_txt.text = String(currentScore);
    }
    saveData();
    }
    function init():void
    {

    saveDataObject = SharedObject.getLocal("test");
    currentScore = 100;




    if (saveDataObject.data.savedScore == null)
    {
    trace("No saved data yet.");
    saveDataObject.data.savedScore = currentScore;
    }
    else
    {
    trace("Save data found.");
    loadData();
    }


    }

    function saveData():void
    {
    saveDataObject.data.savedScore = currentScore;
    trace("Data Saved!");
    saveDataObject.flush();
    trace(saveDataObject.size);
    }

    function loadData():void
    {
    if(currentScore == 100)
    {
    currentScore = saveDataObject.data.savedScore;
    trace("Data Loaded!");
    }
    else if(currentScore == 0)
    {

    currentScore = saveDataObject.data.savedScore;
    }
    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a dynamic text field that changes from 100 to 0 and vice versa when a button is clicked. I want this number to be saved when exiting the application, but it seems that it's not returning the last clicked value when the application reopens. This is the code, any help please?



      import flash.events.MouseEvent;
      import flash.media.SoundChannel;
      import flash.ui.Mouse;

      var saveDataObject:SharedObject;
      var currentScore:Number;
      options_mc.sound_btn.addEventListener(MouseEvent.CLICK, mute);

      options_mc.test3.addEventListener(MouseEvent.CLICK, test3);
      init();
      function mute(event:MouseEvent)
      {

      if(currentScore == 100)
      {
      currentScore = 0
      options_mc.onoff_txt.text = String(currentScore);

      }
      else if(currentScore == 0)
      {
      currentScore = 100
      options_mc.onoff_txt.text = String(currentScore);
      }
      saveData();
      }
      function init():void
      {

      saveDataObject = SharedObject.getLocal("test");
      currentScore = 100;




      if (saveDataObject.data.savedScore == null)
      {
      trace("No saved data yet.");
      saveDataObject.data.savedScore = currentScore;
      }
      else
      {
      trace("Save data found.");
      loadData();
      }


      }

      function saveData():void
      {
      saveDataObject.data.savedScore = currentScore;
      trace("Data Saved!");
      saveDataObject.flush();
      trace(saveDataObject.size);
      }

      function loadData():void
      {
      if(currentScore == 100)
      {
      currentScore = saveDataObject.data.savedScore;
      trace("Data Loaded!");
      }
      else if(currentScore == 0)
      {

      currentScore = saveDataObject.data.savedScore;
      }
      }









      share|improve this question













      I have a dynamic text field that changes from 100 to 0 and vice versa when a button is clicked. I want this number to be saved when exiting the application, but it seems that it's not returning the last clicked value when the application reopens. This is the code, any help please?



      import flash.events.MouseEvent;
      import flash.media.SoundChannel;
      import flash.ui.Mouse;

      var saveDataObject:SharedObject;
      var currentScore:Number;
      options_mc.sound_btn.addEventListener(MouseEvent.CLICK, mute);

      options_mc.test3.addEventListener(MouseEvent.CLICK, test3);
      init();
      function mute(event:MouseEvent)
      {

      if(currentScore == 100)
      {
      currentScore = 0
      options_mc.onoff_txt.text = String(currentScore);

      }
      else if(currentScore == 0)
      {
      currentScore = 100
      options_mc.onoff_txt.text = String(currentScore);
      }
      saveData();
      }
      function init():void
      {

      saveDataObject = SharedObject.getLocal("test");
      currentScore = 100;




      if (saveDataObject.data.savedScore == null)
      {
      trace("No saved data yet.");
      saveDataObject.data.savedScore = currentScore;
      }
      else
      {
      trace("Save data found.");
      loadData();
      }


      }

      function saveData():void
      {
      saveDataObject.data.savedScore = currentScore;
      trace("Data Saved!");
      saveDataObject.flush();
      trace(saveDataObject.size);
      }

      function loadData():void
      {
      if(currentScore == 100)
      {
      currentScore = saveDataObject.data.savedScore;
      trace("Data Loaded!");
      }
      else if(currentScore == 0)
      {

      currentScore = saveDataObject.data.savedScore;
      }
      }






      actionscript-3 flash






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '13 at 2:14









      Sam

      59110




      59110
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          function loadData():void
          {
          currentScore = saveDataObject.data.savedScore;
          trace("Data Loaded!");
          if (options_mc.onoff_txt) options_mc.onoff_txt.text=String(currentScore);
          }


          Apparently you've missed the line that immediately writes the score to text field. You are seemingly doing the saving right.






          share|improve this answer





















          • Thank you so much!
            – Sam
            Nov 16 '13 at 4:16


















          up vote
          0
          down vote













          As3
          (Input.text)
          (Dynamic.text)
          (Button save)



          If input text not blank 
          Saved //
          If input text blank
          Loaded //
          If moving next frame
          Dynamic text still exists //
          If reopen app
          Loaded





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20013833%2fhow-do-i-save-a-dynamic-text%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            function loadData():void
            {
            currentScore = saveDataObject.data.savedScore;
            trace("Data Loaded!");
            if (options_mc.onoff_txt) options_mc.onoff_txt.text=String(currentScore);
            }


            Apparently you've missed the line that immediately writes the score to text field. You are seemingly doing the saving right.






            share|improve this answer





















            • Thank you so much!
              – Sam
              Nov 16 '13 at 4:16















            up vote
            0
            down vote



            accepted










            function loadData():void
            {
            currentScore = saveDataObject.data.savedScore;
            trace("Data Loaded!");
            if (options_mc.onoff_txt) options_mc.onoff_txt.text=String(currentScore);
            }


            Apparently you've missed the line that immediately writes the score to text field. You are seemingly doing the saving right.






            share|improve this answer





















            • Thank you so much!
              – Sam
              Nov 16 '13 at 4:16













            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            function loadData():void
            {
            currentScore = saveDataObject.data.savedScore;
            trace("Data Loaded!");
            if (options_mc.onoff_txt) options_mc.onoff_txt.text=String(currentScore);
            }


            Apparently you've missed the line that immediately writes the score to text field. You are seemingly doing the saving right.






            share|improve this answer












            function loadData():void
            {
            currentScore = saveDataObject.data.savedScore;
            trace("Data Loaded!");
            if (options_mc.onoff_txt) options_mc.onoff_txt.text=String(currentScore);
            }


            Apparently you've missed the line that immediately writes the score to text field. You are seemingly doing the saving right.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '13 at 4:11









            Vesper

            16.6k42749




            16.6k42749












            • Thank you so much!
              – Sam
              Nov 16 '13 at 4:16


















            • Thank you so much!
              – Sam
              Nov 16 '13 at 4:16
















            Thank you so much!
            – Sam
            Nov 16 '13 at 4:16




            Thank you so much!
            – Sam
            Nov 16 '13 at 4:16












            up vote
            0
            down vote













            As3
            (Input.text)
            (Dynamic.text)
            (Button save)



            If input text not blank 
            Saved //
            If input text blank
            Loaded //
            If moving next frame
            Dynamic text still exists //
            If reopen app
            Loaded





            share|improve this answer



























              up vote
              0
              down vote













              As3
              (Input.text)
              (Dynamic.text)
              (Button save)



              If input text not blank 
              Saved //
              If input text blank
              Loaded //
              If moving next frame
              Dynamic text still exists //
              If reopen app
              Loaded





              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                As3
                (Input.text)
                (Dynamic.text)
                (Button save)



                If input text not blank 
                Saved //
                If input text blank
                Loaded //
                If moving next frame
                Dynamic text still exists //
                If reopen app
                Loaded





                share|improve this answer














                As3
                (Input.text)
                (Dynamic.text)
                (Button save)



                If input text not blank 
                Saved //
                If input text blank
                Loaded //
                If moving next frame
                Dynamic text still exists //
                If reopen app
                Loaded






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 11 at 3:01









                Stephen Rauch

                27.3k153156




                27.3k153156










                answered Nov 11 at 2:33









                Yusuf

                1




                1






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20013833%2fhow-do-i-save-a-dynamic-text%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine