actionscript 3 - Manipulate data object in a itemrenderer - Adobe Flex 4 -
i have simple itemrenderer following code:
<?xml version="1.0" encoding="utf-8"?> <s:itemrenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" autodrawbackground="true" width="90" height="90"> <s:vgroup horizontalalign="center"> <mx:image source="{data.photo}" tooltip="{data.name}" /> </s:vgroup> </s:itemrenderer>
i manipulate data object before it's binded image attributes (source , tooltip). this, modified code in way:
<?xml version="1.0" encoding="utf-8"?> <s:itemrenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" autodrawbackground="true" width="90" height="90" initialize="itemrenderer1_initializehandler(event)"> <fx:script> <![cdata[ import mx.events.flexevent; protected function itemrenderer1_initializehandler(event:flexevent):void { var obj:object = this.data; //here manipulation } ]]> </fx:script> <s:vgroup horizontalalign="center"> <mx:image source="{data.photo}" tooltip="{data.name}" /> </s:vgroup> </s:itemrenderer>
when try access this.data object, it's empty! there way manipulate data object before binding? don't have use this.data, cannot find other object edit
another solution override set data function, this:
<?xml version="1.0" encoding="utf-8"?> <s:itemrenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" autodrawbackground="true" width="90" height="90" creationcomplete="itemrenderer1_creationcompletehandler(event)" > <fx:script> <![cdata[ import mx.events.flexevent; import valueobjects.product; [bindable] private var prd:product; override public function set data(value:object):void { super.data = value; //here can access this.data object! this.prd = this.data product; } ]]> </fx:script> <s:vgroup horizontalalign="center"> <mx:image source="{prd.photo}" tooltip="{prd.name}" width="70" /> <mx:label text="{prd.name}"/> </s:vgroup>
Comments
Post a Comment