Flex override public function set data

actionscript-3apache-flexdatagrid

I have a datagrid with itemRenderer in datagridcolumn as my custom component(c1). I am getting the dataprovider data in custom component by overriding the set data function, it is fine. But now my custom component(c1) is also having another custom component(c2).

Now the doubt is – how to get the dataprovider data in c2 component?

Thanks in advance.

Best Answer

Assuming c1 is the item renderer, and c2 is a child of the itemRenderer, all you need to do is something like, binding the child component's data property to the parents data property, or just passing in just the necessary data. You may not be able to do this in the set data function as the child component may not exsist yet, so you may have to add a check to make sure the child component exsists & also set the data when the child is created.

<mx:Canvas>
   <mx:Script>
     <![CDATA[
         override public function set data(value:Object):void{
               super.data = value;
               //do whatever w/ the data
         }
      ]]>
    </mx:Script>
    <components:MyCustomComponent id="c2" data="{data}" />
</mx:Canvas>

(note this is psuedo code and probably full of typos as well)