5 Replies Latest reply on Nov 21, 2006 3:14 PM by Newsgroup_User

    syntax question

    noviceone
      I'm trying to use the following variable in a statement. It doesn't work and I think I have my syntax wrong.

      var activeButton:String = "btnWhoWeAre_mc";
      [activeButton]button_txt.setTextFormat(button_fmt);

      It works if I hard code it. So how do I use a variable on the front end of this statement?

      th
        • 1. syntax question
          neil manuell Level 1
          yes, the square brackets indicate a property of an object. You have defined the property, but not the object...

          assuming that 'this' is the scope of the [activeButton] property

          var activeButton:String = "btnWhoWeAre_mc";
          this[activeButton]button_txt.setTextFormat(button_fmt);
          • 2. syntax question
            noviceone Level 1
            in this case, I want the square brackets to define the object.
            btnWhoWeAre_mc is the object.
            I changed the name of the var for clarity;

            var activeButtonObject:String = "btnWhoWeAre_mc";
            [activeButtonObject]button_txt.setTextFormat(button_fmt);

            How do I define an object that has been stored in a var using this format? If not square brackets, what?
            th
            • 3. Re: syntax question
              Level 7
              > var activeButtonObject:String = "btnWhoWeAre_mc";
              > [activeButtonObject]button_txt.setTextFormat(button_fmt);

              Did you not even bother reading the reply to you? Why ask questions if you
              ignore the answers?
              --
              jeckyl


              • 4. Re: syntax question
                noviceone Level 1
                of course I read the reply. Because what was stated did not work, I assumed I was misunderstood.

                So I still have the problem.

                I have five movie clips that I'm using for buttons. The active button is to have a different color to let the user know where he is currently on the site. So for each onRelease for each button I reset the var "activeButton" and set its textfield color.

                this[activeButton]button_txt.setTextFormat(button_fmt); will not work because this refers to the calling function onRelease.

                _root or _parent didn't work either (its on the main timeline). Thus my frustration. Please bear with me.

                Thanks.

                th (code below)

                btnWhoWeAre_mc.onRelease = function():Void
                {
                [activeButton]button_txt.setTextFormat(button_fmt);
                activeButton = this;
                this.button_txt.setTextFormat(mouseActive_fmt);

                _root.attachMovie
                ("mcWhoWeAreButtons","WhoWeAreButtons_mc",10); //sub navbar
                with(WhoWeAreButtons_mc) //place the movie clip sub menu
                {
                _x=296;
                _y=115;
                }
                }
                • 5. Re: syntax question
                  Level 7
                  > [activeButton]button_txt.setTextFormat(button_fmt);

                  So you still haven't read the initial reply here that told you this was
                  incorrect and showed you the correct way to do it
                  --
                  jeckyl