3 Replies Latest reply on Aug 2, 2009 12:53 AM by selvakumar p

    currentTarget concatenation issue

    cdub Level 1

      I'm just curious as to why a certain concatenation works in a trace statement but not when I use it to actually do something. Here's what I mean:


                  private function onClick(e:MouseEvent):void
                      var target = e.currentTarget;
                      trace(target + "On"); //this traces correctly, shows the name of the button with On appended to the end
                      target + "On".alpha = 1; //this gets on error in Flex



      Anyone know why 'trace(target + "On");' returns 'buttonNameOn' but I can't actually access it. What do I need to do to make this work?

        • 1. Re: currentTarget concatenation issue
          Flex harUI Adobe Employee

          Trace will try to evaluate everything to a string so target.toString() is called.


          On the next line you're trying to add a string to an object.  The following might work better (assumes ButtonNameOn is a variable on the current document)


          this[target.toString() + "On"].alpha = 1


          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          1 person found this helpful
          • 2. Re: currentTarget concatenation issue
            cdub Level 1

            Thanks for getting back to me. I used your code:


                            var target = e.currentTarget;
                            trace(target + "On");
                            this[target.toString() + "On"].alpha = 1;


            And it builds just fine. However, when I click the button it throws ReferenceError: Error #1069: Property AnimTest0.HBox6.refineBtnOn not found on AnimTest and there is no default value...


            Could it be because it's not expecting a string? Anyone know what else needs to be done?

            • 3. Re: currentTarget concatenation issue
              selvakumar p

              if u haven't defined the type for target then target will said to have  the button  object in which the event has happened.

              as said in the post trace deals only with strings, hence the concatenation works.

              in the line target.tostring+"on".alpha u r accessing a undefined object buttonon property alpha;

              u can't append strings to object refrences and access other objects.

              if this post answers mark as such