3 Replies Latest reply on Mar 17, 2009 11:19 AM by Newsgroup_User

    Referencing THIS object from a function?

    rpeters1983
      This may be more of a general programming question, but I this is being done in AIR.

      myObject.addEventListener(MYEVENT, function ():void {

      // function code
      this.height = 200; // <----------- THIS LINE
      });

      I need to reference the Application. When I use "this" it is obviously not referencing the Application (in my case, WindowedApplication) object. I'm sort of new to actionscript and flex. I need to change the height after the event has fired. Thanks.

      Ryan
        • 1. Referencing THIS object from a function?
          BuG300K
          Could you be looking for the apply() method?

          function.apply(object,[arg1,arg2])

          function would be the function you're calling
          object would be the object you're going to refer to as 'this'
          and [arg1,arg2] is an array of arguments you are passing (If any)

          Hope this helped!

          Edit :

          Also - you could pass your event object to the function and use the event.target property to access the element that called the function, like the following :

          • 2. Referencing THIS object from a function?
            Ansury Level 3
            You might want to do this:

            Application.application.height = 200;

            Or it may start with WindowedApplication with AIR, I forget.
            • 3. Re: Referencing THIS object from a function?
              Level 7

              "rpeters1983" <webforumsuser@macromedia.com> wrote in message
              news:gpm1il$51c$1@forums.macromedia.com...
              > This may be more of a general programming question, but I this is being
              > done in
              > AIR.
              >
              > myObject.addEventListener(MYEVENT, function ():void {
              >
              > // function code
              > this.height = 200; // <----------- THIS LINE
              > });

              This is code from an AIR app I have:

              private function setLayoutProperties():void{

              switch(appWidth) {

              case FAT:

              this.x=areaRect.x;

              this.width=areaRect.width;

              toggleWindow.setStyle('icon', leftArrow);

              optionsButton.toolTip='Shrink window';

              //buttonHolder.setStyle('borderStyle', 'solid');

              //testDataGrid.includeInLayout=true;

              //testDataGrid.visible=true;

              break;

              case SKINNY:

              this.width=smallWidth;

              toggleWindow.setStyle('icon', rightArrow);

              optionsButton.toolTip='Grow window'

              //testDataGrid.includeInLayout=false;

              //testDataGrid.visible=false;

              //buttonHolder.setStyle('borderStyle', 'none');

              }

              }



              Maybe you will find it helpful;



              Amy