3 Replies Latest reply on Oct 1, 2008 6:59 AM by ac361

    Add custom property to "data" object

    ac361 Level 1
      Hi. I'm trying to figure out how to add a custom property to the data object that's available in my event handler code. After the user clicks a button in a datagrid itemRenderer, I need to add a property to the data object and then read that value in the call to "override public function set data()" function; if that property exists, the column will have a value set; otherwise, it will be blank.

      What's the syntax of adding a custom property to the data object? Thanks.
        • 1. Re: Add custom property to "data" object
          Level 7

          "curious_Lee" <webforumsuser@macromedia.com> wrote in message
          news:gbtdkh$1ci$1@forums.macromedia.com...
          > Hi. I'm trying to figure out how to add a custom property to the data
          > object
          > that's available in my event handler code. After the user clicks a button
          > in a
          > datagrid itemRenderer, I need to add a property to the data object and
          > then
          > read that value in the call to "override public function set data()"
          > function;
          > if that property exists, the column will have a value set; otherwise, it
          > will
          > be blank.
          >
          > What's the syntax of adding a custom property to the data object? Thanks.

          The data object is an object that contains the data for the entire row. So
          it contains whatever you put into the dataProvider for that item.


          • 2. Re: Add custom property to &quot;data&quot; object
            Peter Lorent Level 2
            So let's say you fill your renderers with custom objects of type Product and that object has a property _selected:

            package {
            //import statements left out...
            public class Product {

            private var _selected:Boolean;

            public function Product()
            {
            }

            public function set selected(b:Boolean):void
            {
            _selected = selected;
            }

            public function get selected():Boolean
            {
            return _selected;
            }
            }
            }

            Now in your renderer:

            private var product:Product;
            override public function set data(value:Object):void
            {
            super.data = value;
            product = value as Product;
            }

            When you retrieve the renderer you can set the property selected. In the renderer you can use the 'dataChange' event to inspect whether the selected property is true or false.
            • 3. Add custom property to &quot;data&quot; object
              ac361 Level 1
              Thanks. The solution was to use this in the itemRenderer's button click event handler,

              myDataGrid.selectedItem.UploadFileName = "someFile.jpg";

              Then you can access that in the overridden set data function inside the itemRenderer section, making sure to set the TextInput to blank if the data.UploadFileName is undefined or null. This will prevent the recycled itemRenderers from setting other TextInput fields to the same value.

              By the way, the reason to use the selectedItem vs. "data" object: The data object is out of scope.