4 Replies Latest reply on Mar 23, 2007 12:36 PM by BobAchgill

    this[ ]

    BobAchgill
      Why is the output on the last line of these traces not the same as the next to last line of output?

      trace("countLang2Next = " + countLang2Next) // output: countLang2Next = 2
      trace("Menu_Lang2.Lang2_" + countLang2Next) // output: Menu_Lang2.Lang2_2
      trace(Menu_Lang2.Lang2_2) // output: RUS
      trace(this["Menu_Lang2.Lang2_" + countLang2Next]) // output: undefined
        • 1. Re: this[ ]
          Level 7
          BobAchgill,

          > Why is the output on the last line of these traces not the same
          > as the next to last line of output?

          By the looks of it, there is no Menu_Lang2.Lang2_2 property in whatever
          object this points to. Perhaps that property is in the parent object of
          this one, in which case ...

          this._parent["Menu_Lang2.Lang2_" + countLang2Next]

          .... might be what you need.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."

          >
          > trace("countLang2Next = " + countLang2Next) //
          > output:
          > countLang2Next = 2
          > trace("Menu_Lang2.Lang2_" + countLang2Next) // output:
          > Menu_Lang2.Lang2_2
          > trace(Menu_Lang2.Lang2_2)
          > //
          > output: RUS
          > trace(this["Menu_Lang2.Lang2_" + countLang2Next]) // output:
          > undefined
          >


          • 2. Re: this[ ]
            BobAchgill Level 1
            I tried the this._parent[ that you suggested.
            See last trace line. The output is still "undefined". It is till not finding the contents of the variable.

            Does it help to say that the variable was created as a result of this LoadVars statement (see below)? From the traces it appears that the data is there but I just can't seem to get at it programmactically using "this."

            /////////
            var Menu_Lang2:LoadVars = new LoadVars();
            Menu_Lang2.load("Menu_Lang2_" + this["Lang1_" + countLang1] + ".txt", _root);
            /////////

            trace("countLang2Next = " + countLang2Next) // .............output: countLang2Next = 2
            trace("Menu_Lang2.Lang2_" + countLang2Next) //........ output: Menu_Lang2.Lang2_2
            trace(Menu_Lang2.Lang2_2) //........................................ output: RUS
            trace(this["Menu_Lang2.Lang2_" + countLang2Next]) // output: undefined
            trace(this["Menu_Lang2.Lang2_" + countLang2Next]) // output: undefined

            trace(this._parent["Menu_Lang2.Lang2_" + countLang2Next]) // output: undefined
            • 3. Re: this[ ]
              Level 7
              BobAchgill,

              >I tried the this._parent[ that you suggested.
              > See last trace line. The output is still "undefined". It is till not
              > finding the contents of the variable.

              Aha. I think I see it.

              > trace(this["Menu_Lang2.Lang2_" + countLang2Next]) // output: undefined

              The Menu_Lang2 part doesn't change. So use that as your base reference,
              rather than this (the this is implied).

              Menu_Lang2["Lang2_" + countLang2Next]

              Note that the brackets replace the normal dot operator.


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: this[ ]
                BobAchgill Level 1
                Menu_Lang2["Lang2_" + countLang2Next]

                Thank you David, It works!