9 Replies Latest reply on Oct 15, 2007 7:00 AM by kglad

    Trouble with variables

    Berall Level 1
      Hi everyone. So, here we go, im about to pull what little hair Ive got left. I figured out how to accomplish the script, Im just screwing up somewhere in the execution. Basically, I’m trying to load a variable. The challenge is that this variable has 3 different values depending on what set its from. To put in another way, I have variable A, in Sets 1, 2, and 3. I created a text object to display the information. To choose which set of data, I have a three buttons attached to the variable “menu state” Each button either sets menustate to 1, 2 or 3.

      To that text object, I simply stated:
      Text1 = LAS + menustate.

      In my noodle, this should have come out as Text1 = LAS1 (1 is menustate’s default) However, I keep getting the error NaN (whatever that means) When I set Text1 = LAS1 it brings up the correct data from the loaded TXT file. However, when I try to get to LAS1 dynamically, it insists on the error. Its even worse, If I say Text1 = “LAS” + menustate, Text1 displays LAS1 instead of the loaded data LAS1.

      Any help fellas? Am I just barking up the wrong tree entirely?

        • 1. Re: Trouble with variables
          kglad Adobe Community Professional & MVP

          • 2. Re: Trouble with variables
            Berall Level 1
            I will definitely try this. What do the brackets do? What is their function?
            • 3. Re: Trouble with variables
              clbeech Level 3
              The brackets are an 'access operator' and can specify variables, properties or objects with an Objects array list, in this case things belonging to 'this' or the main timeline.

              Since you are trying to 'concatenate' a String and a Number, you need to use the access operator to specify the variable your looking for by name, accessing the contents of the resulting variable name, and assigning it to the new variable 'Text1'.
              • 4. Re: Trouble with variables
                Berall Level 1
                holy cow, you guys rock more than a teed off donkey! That did it, thanks you kglad!
                • 5. Re: Trouble with variables
                  kglad Adobe Community Professional & MVP
                  you're welcome.
                  • 6. Re: Trouble with variables
                    Berall Level 1
                    kglad: It appears, I spoke too soon, I created a small test flash, and your code additons worked great. But now, when I implemented it in the actual work file...things are going screwey again.

                    This is the code specificaly:
                    numLAScalc = this["LAS_KPI_"+_root.KPIstate+"_value"];

                    Where numLAScalc is the calculation. This calculation is fed on the next frame into the text1 variable that displays the info.

                    The data in the external file is called LAS_KPI_(1 or 2 or 4)_value (example LAS_KPI_2_value)
                    _root.KPIstate is a variable in the 0 level that buttons manipulate to switch from set 1, 2, and 4.

                    I should mention that this code is happening inside a movie (hence the _root. reference)

                    By playing around, when I took the "this" part out of the code, the code worked as it did on my first post: it put all the variables together into the name of the data variable, but when it got to the text variable, it refused to display correctly. Only now, instead of NaN, the error I get (when the code includes the "this" is "undefined"

                    any help? Im so close....
                    • 7. Re: Trouble with variables
                      kglad Adobe Community Professional & MVP
                      1. are you accessing those variables AFTER it's defined? ie, if they're loaded from a text file, is loading complete?

                      2. on what timeline are those variable's defined (relative to your code's location)? ie, if you're variable is not on "this" timeline, you need to change "this" to the timeline that contains those variables.
                      • 8. Re: Trouble with variables
                        Berall Level 1
                        Ive done everything I can think of. Relatively speaking, I define the variable textcalc on frame 5, and then on frame 12 (after pressing a button that in an on mouse event states that KPIstate = 1, and then to go to and play frame 10. The code on that frame looks like this:
                        textcalc = _root["A"+KPIstate];

                        On the next line, I specify where the variable is (inside a movie).
                        tellTarget ("_root.txtLAS.txtboxLAS") {
                        numLAS = textcalc;

                        The variable is in a text box (named txtboxLAS) and the variable for the text itself is named numLAS. I therefore set numLAS to equal textcalc which should make it equal the variable I called up from the data file (back in frame 5)

                        Of course, all I get the textbox to do, is just display the variable name. That is, without the "this." If I leave in the "this." before the equation (I tried _root as well) the text box displays "undefined"

                        any ideas?
                        • 9. Re: Trouble with variables
                          kglad Adobe Community Professional & MVP
                          post a link to your fla and specify the location of the problem code.