19 Replies Latest reply on Sep 24, 2006 1:27 PM by kglad

    variable usage

    Robert Barr Level 1
      This may sound stupid, but I am trying to get variables from a txt file and load them into an actual variable that is a number in the first LoadVars situation. I must be doing something wrong. I would like those variables to be global as well.
      In the second instance, I can get the information into the textfields, but I want to change the the names of what goes into the text fields when I hit the button and the names of the variables are the same but with a different number at the end.
      var mynewLV:LoadVars = new LoadVars();
      mynewLV.onLoad = function() {
      firstholder.text = this.work1;
      secondholder.text = this.work2;
      thirdholder.text = this.work3;
      var flisting:Number = Number(firstholder.text);
      var guesstime:Number = flisting + flisting;
      guesswork.text = guesstime + guesstime;

      _global.count = 1;
      var myLV:LoadVars = new LoadVars();
      myLV.onLoad = function (success) {
      if (success) {
      thename.text = this.aname1;
      theaddress.text = this.aaddress1;
      thecity.text = this.acity1;
      thestate.text = this.astate1;
      thezipcode.text = this.azipcode1;
      thephone.text = this.aphone1;
      theemail.text = this.aemail1;
      thename2.text = this.aname2;
      } else {
      thename.text = "There has been an error loading.";
      This is the button code which will work, but I cannot change the number at the end of each variable.
      var lovely = "aname" + count;
      thename.text = myLV.aname3;
      theaddress.text = myLV.aaddress3;
      thecity.text = myLV.acity3;
      thestate.text = myLV.astate3;
      thezipcode.text = myLV.azipcode3;
      thephone.text = myLV.aphone3;
      theemail.text = myLV.aemail3;
        • 1. Re: variable usage
          kglad Adobe Community Professional & MVP
          1. flisting is going to be defined before firstholder's text property is changed by your onLoad handler.

          2. count is not being used in your button handler in any meaningful way.

          3. do you want your button handler to define the text property of your various textfields and do you want it to use myLV.aname1, myLV.aname2, myLV.aname3 to assign the text property of thename, for example? do you want it to use those variables incrementing with each button release? do you want to restart with aname1 if the button is released after aname3 has been used?
          • 2. Re: variable usage
            Robert Barr Level 1
            I do not understand why flisting will be populated before onLoad since it appears a ways after the onLoad handler.
            Anyway, how would you recommend I get the information from a txt file into a numeric variable so that I can use it globally to count with?
            Count was originally what I was trying to use as a global variable but I couldn't get my text fields populated by using a variable in the line thename.text = myLV.(whatever the variable was, which was one to change the count each time the button was released.
            I can understand the way to get the button itself to work and keep count. What I am trying to do is to populate my text fields with variables within the myLV array but only certain ones at a time. Every eighth variable has the same name but with a different number.
            • 3. Re: variable usage
              kglad Adobe Community Professional & MVP
              your mynewLV.load("vars/worker.txt") statement is asynchronous, which means it does NOT complete execution before statements after it execute. to remedy place those flisting statements in your onLoad handler.

              i still don't know what your button to do because you didn't answer the questions i asked in my message above. but my best guess is you want to use something like:

              • 4. Re: variable usage
                Robert Barr Level 1
                Thank you, I am not sure but that looks a lot like what I wanted to do, but I may have been using paragraph markers instead of brackets. One other question. If I move those into the Load function, can I place them directly into global variables and use them instead of the count that I have in my button function?
                • 5. Re: variable usage
                  Robert Barr Level 1
                  I want to thank you, because that was what I was trying to do with the button. However, I am still trying to figure out how to bring something in from a text file and place it immediately into a global variable and use it.
                  • 6. Re: variable usage
                    kglad Adobe Community Professional & MVP
                    you're welcome.

                    you should have no problems defining a global variable in flash using a variable/value from a text file. you would use something like:

                    • 7. Re: variable usage
                      Robert Barr Level 1
                      Thank You!! That was the information I needed, because I couldn't figure out how to get it to work the way I was trying to do it. Is that the same way you would get the number from a text file into a constant?
                      • 8. Re: variable usage
                        kglad Adobe Community Professional & MVP
                        yes, if you had a text file containing &yourVar=77.1& that you loaded using the LoadVars() class you would use:

                        • 9. Re: variable usage
                          Robert Barr Level 1
                          I really want to thank you for your help. You have been very helpful. Just one last question. Does making the variable a global one also make it a constant?
                          • 10. Re: variable usage
                            kglad Adobe Community Professional & MVP
                            no, a global variable can be changed at any time. if you still want the variable to be global when you change it, you must again prefix it with _global in your line redefining its value. if you no longer want it to be global, don't use a prefix. and if you want it to be local (to a function, for example), prefix it with var .
                            • 11. Re: variable usage
                              Robert Barr Level 1
                              I thank you for your statement, but it did not really address the issue of a constant. Yet, I need to find out something else now. I want to be able to use a global variable every time my swf files changes in _level0. I have tried to get it to work by using different levels, but when I do, _level0 stays on the screen when I bring in another swf into another level.
                              • 12. Re: variable usage
                                kglad Adobe Community Professional & MVP
                                the first word in my previous response ("no...") answered your question. i then continued to explain the answer. and i gave a more thorough explaination of global, local and unspecified variables.

                                perhaps you and i are using the word "constant" to mean two different things. a constant is a value that doesn't change. for example, Math.PI is a constant. _global.flisting is a variable that's not a constant. it may contain a value that you never change, but it's still a variable that COULD be changed, and therefore is not a constant. even the code at the end of this message would not change flisting to be a constant.

                                now, if you unload your _level0 swf, all data stored in it (including all global variables) will be removed. you could use the sharedobject to store the value of your variable(s) but it my be better to use _level0._visible=0 to maintain the existance of all objects in your _level0 swf without it interfering with the appearance of swfs loaded into higher levels.

                                • 13. Re: variable usage
                                  Robert Barr Level 1
                                  Thank you very much for clearing that up. Where exactly would the _level0._visible=0 be put ? I though it would be put on the button I use to load the next page just before the loadMovieNum() but it didn' seem to preserve my variables. I am not too clear on the way a shared object is utilized. I looked in the documentation and such and I still am unclear as to how that actually works.
                                  • 14. Re: variable usage
                                    kglad Adobe Community Professional & MVP
                                    if you use loadMovieNum and load into any _level OTHER than 0, your variables will be preserved.

                                    the _level0._visible statement makes everything in your _level0 swf NOT visible to eliminate your issue with "..but when i do, _level0 stays on the screen...".

                                    you can put the _level0._visible=0 statement anywhere. you should have it execute at the same time as you execute your loadMovieNum() statement.
                                    • 15. Re: variable usage
                                      Robert Barr Level 1
                                      So then when referencing the variables from _level0 in _level5 does that mean I have to use the _level0 in front of the variable in order to use it? I tried using my _global.count inside a _level5 swf and I get a Nan message in my trace.
                                      • 16. Re: variable usage
                                        Robert Barr Level 1
                                        Just so that you can see what I am trying to do, hopefully the code is attached
                                        • 17. Re: variable usage
                                          kglad Adobe Community Professional & MVP
                                          from _level5 you need to use the path to variables in _level0 (ie, _level0.count) except when those variables are global. you can then simply use the variable as if it were local to your _level5 timeline (ie, count).

                                          i don't know what trace is causing a problem in your posted code. i can see the your loadMovie() statement should be loadMovieNum() but i doubt this is causing your problem.
                                          • 18. Re: variable usage
                                            Robert Barr Level 1
                                            I just decided to let each page load its own global variable and have everything work in _level0. It jsut seemed to be the easier way to go and it makes it fairly simple. Thank you much for your help.
                                            • 19. Re: variable usage
                                              kglad Adobe Community Professional & MVP
                                              you're welcome.