3 Replies Latest reply on Jan 25, 2009 7:57 PM by Newsgroup_User

    Confused on Override Function and "set" method ??

    WestSide
      Hi,

      I am creating this itemRenderer for my tree control. I am learning from some examples and I wanted to know if someone can explain this code and specifically where it gets the value that you pass in to the function. I am not calling this function explicitly so can someone explain:

      1. How and when it gets called?

      2. How do you pass data in since I am not calling it explicitly

      public class MyRenderer extends TreeItemRenderer {

      override public function set data(value:Object):void {
      super.data = value;
      }

      }

      I understand it is setting the "data property" but still unclear on my questions above.

      Any help appreciated.

      -Westside
        • 1. Re: Confused on Override Function and "set" method ??
          Level 7

          "WestSide" <webforumsuser@macromedia.com> wrote in message
          news:glgnh9$cuc$1@forums.macromedia.com...
          > Hi,
          >
          > I am creating this itemRenderer for my tree control. I am learning from
          > some
          > examples and I wanted to know if someone can explain this code and
          > specifically
          > where it gets the value that you pass in to the function. I am not
          > calling
          > this function explicitly so can someone explain:
          >
          > 1. How and when it gets called?
          >
          > 2. How do you pass data in since I am not calling it explicitly
          >
          > public class MyRenderer extends TreeItemRenderer {
          >
          > override public function set data(value:Object):void {
          > super.data = value;
          > }
          >
          > }
          >
          > I understand it is setting the "data property" but still unclear on my
          > questions above.

          There is no value in overriding set data() in this way unless you are _also_
          doing something else in here, since essentially what this says is to pass
          the value variable through to the original data property on the original
          class.

          Typically, what I do is something more like this:

          private var _dataChanged:Boolean=true;
          private var _data:Object;

          override public function set data(value:Object):void {
          if (value != _data) {
          _data = value;
          super.data = value;
          _dataChanged = true;
          //something has changed, schedule a call to commitProperties
          invalidateProperties();
          }
          }

          override protected function commitProperties():void {
          //make sure to run the existing commitProperties!
          super.commitProperties();
          //now set whatever needs to be set based on what changed
          if (_dataChanged && data.hasOwnProperty('someValue')) {
          myLabel.text = data['someValue'];
          }
          }

          HTH;

          Amy


          • 2. Re: Confused on Override Function and &quot;set&quot; method ??
            WestSide Level 1
            Hi,

            Thanks for the reply, this makes more sense now.

            -Westside
            • 3. Re: Confused on Override Function and &quot;set&quot; method ??
              Level 7

              "WestSide" <webforumsuser@macromedia.com> wrote in message
              news:glj8rm$grm$1@forums.macromedia.com...
              > Hi,
              >
              > Thanks for the reply, this makes more sense now.

              You're welcome. You may want to check out the links for Q2:
              http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf