views:

253

answers:

2

Hi,

how can access/pass a value object in a custom itemrenderer? The item renderer represents a field in my datagrid and i want to be able access properties from my VO.

Thanks

+1  A: 

You will want to override the set data method of the item renderer:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo">
    <fx:Script>
     <![CDATA[

      //Strongly typed VO for use in binding.
      [Bindable]
      private var myValueObject:MyValueObject;

      override public function set data(value:Object) : void
      {
       //we don't want to update if the value is the exact same.
       if(data === value)
        return;

       //you could simply access the data property but I think
       //it is nicer to have strong typing for code hints
       super.data = myValueObject = value;
       validateNow();
      }
     ]]>
    </fx:Script>
    <mx:Label text="{myValueObject.name}"/>
</mx:Canvas>
Joel Hooks
thanks but its not the actual contents of the dataprovider i want to update, its actually an object i create in another part of the application.
combi001
add the proper VO as a property of the data that is being rendered. Item renderers should render a single data object and perhaps dispatch events. When I want renderers to affect other data in an application I dispatch an appropriate event that triggers that sort of reaction.you might update your question to be a little clearer in regards to your issue.
Joel Hooks
A: 
Tim D