The framework calls the set value function often for item renderers. You need to *override* the function and that means keeping the same method signature, and using the "override" declaration.
Regarding the "name", all row-level states must be set from the dataProvider item. You will need the name value in your item. Find a full example to look at. Tracy -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of gbkpicasso Sent: Thursday, June 26, 2008 4:01 PM To: [email protected] Subject: [flexcomponents] Re: Slider in a Datagrid resets when Datagrid is scrolled. Tracy In trying to follow your best practice, and this being my first attempt at a Flex Component, I've been having trouble the past few days putting this together. I tried to look at the livedocs example for the commitProperties() and apply it to my example but I'm having trouble making that happen. I added two private vars to my Component code: private var _value:Number; private var _name:String; I see that I can override the set value function for "value" property of my slider: public function set value(val:Number):void { trace("I'm in set value); _value = val; invalidateProperties(); } But there is no override for the slider's "name" property. So I created a setName(n) function, but I'm not sure how to call this from my main application. public function setName(n:String):void { trace("I'm in setName); _name = n; invalidateProperties(); } How do I or When is the set value() function called? I didn't have to manually call the set data(). It was called for me when I assigned a new object with a name and value for the slider. I put trace statement in the set value but it never seemed to be called from anything. I added the override commitProperties() function. But since set value is never called and I'm sure how to call it from my main application since it's a column inside a datagrid. override protected function commitProperties():void { trace("In commitProperties); super.commitProperties(); mySlider.value = _value; mySlider.name = _name; } Am I going in the wrong direction here? I think I'm close but just missing a few pieces, of code that is. Ha Ha. Thanks for you time and help Greg --- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote: > > Whoops, sorry, looking at your code, your are headed in the right > direction. Maybe debug to see what is resetting the slider value? > > Also, best practice is to store the data vlue in a local var, and call > invalidateProperties(). Do the work in commitProperties(). Set data > gets called very often, but the call to commitProperties is optimized by > the framework. > > Tracy > > -----Original Message----- > From: [email protected] > [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt > Sent: Tuesday, June 24, 2008 2:35 PM > To: [email protected] > Subject: RE: [flexcomponents] Slider in a Datagrid resets when Datagrid > is scrolled. > > Item renderers are recycled, so all row-level state must be data- driven. > > Your slider must obtain its value from a property on the dataProvider > item, and set that value in the commitProperties or updateDisplayList > methods. > > It must also update that same dataProvider item property value when a > user interacts with the control. > > Find an example of a working itemRenderer and modify that to fit your > needs, rather than attempt to create one from scratch. > > Tracy > > -----Original Message----- > From: [email protected] > [mailto:[EMAIL PROTECTED] On Behalf Of gbkpicasso > Sent: Monday, June 23, 2008 12:19 PM > To: [email protected] > Subject: [flexcomponents] Slider in a Datagrid resets when Datagrid is > scrolled. > > Hello, > I have a HSlider custom component that is used as a column in a > datagrid. If I change the value of a slider and then scroll the > datagrid so that row does not appear, the value of the slider is > reset to it's original value. It does not trigger a change event, it > only visually moves the slider. > This does not happen to rows that are still viewable in the datagrid. > It only happens to rows that are not seen after the datagrid is > scrolled. > How can I keep the sliders from changing back to their original value? > > Thanks > Greg > > I have included my Application code and the custom component code > below. > > //------------------------------------- > // Application code: > //------------------------------------- > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute"> > > <mx:Script> > <![CDATA[ > import mx.collections.ArrayCollection; > > [Bindable] > private var dataLayers:ArrayCollection = new > ArrayCollection( > [ {name:'Data 1',value:'1'}, > {name:'Data 2',value:'1'}, > {name:'Data 3',value:'1'}, > {name:'Data 4',value:'1'}, > {name:'Data 5',value:'1'}, > {name:'Data 6',value:'1'}, > {name:'Data 7',value:'1'}, > {name:'Data 8',value:'1'}, > {name:'Data 9',value:'1'}, > {name:'Data 10',value:'1'}]); > > ]]> > </mx:Script> > <mx:DataGrid dataProvider="{dataLayers}" width="221"> > <mx:columns> > <mx:DataGridColumn > headerText="Name" dataField="name" width="95" /> > <mx:DataGridColumn > headerText="Value" dataField="volumn" itemRenderer="MySlider"/> > > > > </mx:columns> > </mx:DataGrid> > </mx:Application> > > //------------------------------------- > // Custom Component code in a file called MySlider.mxml: > //------------------------------------- > <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" > height="100%"> > <mx:Script> > <![CDATA[ > import mx.events.SliderEvent; > > private function slideChanged(event:SliderEvent):void > { > trace("Slider Changed: " + mySlider.name + ", > Value: " + event.value); > var myEvent:SliderEvent = new SliderEvent > (SliderEvent.CHANGE,true,event.cancelable, event.thumbIndex, > event.value,event.triggerEvent, event.clickTarget,event.keyCode); > dispatchEvent(myEvent); > } > > override public function set data(myVal:Object):void > { > mySlider.value = myVal.volumn; > mySlider.name = myVal.name; > } > ]]> > </mx:Script> > <mx:HSlider id="mySlider" width="100" minimum="0" > maximum="1.25" liveDragging="true" change="slideChanged(event)" /> > </mx:VBox> > > > > ------------------------------------ > > Yahoo! Groups Links > > > > > > > ------------------------------------ > > Yahoo! Groups Links > ------------------------------------ Yahoo! Groups Links
