1 Reply Latest reply on May 4, 2009 2:39 PM by phillipus_rex

    Using "this" in Functions


      I have a function that changes the color of a button when clicked:


        private function buttonColor(Event:MouseEvent):void
                  btn1.styleName = "newColor";


      The code above works fine.



      However, this code does not work:

        private function buttonColor(Event:MouseEvent):void
                  this.styleName = "newColor";            


      I don't understand why this won't work.  Doesn't "this" refer to whatever the function is applied to?

        • 1. Re: Using "this" in Functions
          Boy Carper Level 1

          no, this is the current class your function is in, try SimpleButton(even.target)  (if you used a simplebutton), also make the E of Event lower case otherwise is recognised as the class Event.


          The event.target object is the object that has been clicked. If you use nested movieclips in your button even.target will refer to the nested movieclip, this can be avoided by disabling mouseChildren on the btn1 (btn1.mouseChildren = false;)