You need to move your code that sets the label: criticite.text = ( resultGravite * resultProbabilite ).toString();
into the doShow() routine since that is where the objects get (re)set everytime the grid changes. -doug --- In [email protected], "quantum_ohm" <[EMAIL PROTECTED]> wrote: > > Hello, > > How could I reference a label with a kind of 'selectedIndex' ? > It might sound dummy, but I'd like to follow the idea > (http://blog.dougco.com/category/coding/flex/) used with the > CBs to apply it to a label... > The problem is that the result in the label doesn't stay in its right > place when I scroll the DG. > > Thx > > Here is the code below : > > <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" > horizontalScrollPolicy="off" dataChange="gridScrolled()"> > <mx:Script> > <![CDATA[ > > import mx.controls.DataGrid; > > [Bindable] private var graviteArray:Array = [ > { label:"N/A", data:"0"}, > { label:"Critique", data:"3" }, > { label:"Majeur", data:"2"}, > { label:"Mineur", data:"1"} ]; > [Bindable] private var probabiliteArray:Array = [ > { label:"N/A", data:"0"}, > { label:"20%", data:"1" }, > { label:"40%", data:"2"}, > { label:"60%", data:"3"}, > { label:"80%", data:"4"} ]; > [Bindable] private var resultGravite:int; > [Bindable] private var dgIndex:int; > > private var resultProbabilite:int; > private var monChoix:String = "000"; > > > private function gridScrolled():void{ > if (data != null) { > monChoix = data.choix; > } > doShow( monChoix ); > } > > private function doShow(s:String):void{ > var v1:int = parseInt(s.substr(0,1)); > var v2:int = parseInt(s.substr(1,1)); > var v3:int = parseInt(s.substr(2,1));//????? > > gravite.selectedIndex = v1; > probabilite.selectedIndex = v2; > > if ( gravite.selectedIndex == 0 ) { probabilite.enabled = false; > }else{ probabilite.enabled = true; } > } > > private function resultat():void{ > var n1:int = gravite.selectedIndex; > var n2:int = probabilite.selectedIndex; > dgIndex = this.parentApplication.dgSpec.selectedIndex;//???do I need > this?????? > var n3:int = dgIndex;//????do I need this?????? > > resultGravite = graviteArray[n1].data; > resultProbabilite = probabiliteArray[n2].data; > > data.choix = monChoix = n1.toString() + n2.toString() + > n3.toString(); > > criticite.text = ( resultGravite * resultProbabilite ).toString(); > > doShow( monChoix ); > } > ]]> > </mx:Script> > > <mx:ComboBox id="gravite" width="83" dataProvider="{graviteArray}" > change="resultat()"/> > > <mx:ComboBox id="probabilite" width="70" > dataProvider="{probabiliteArray}" change="resultat()"/> > > <mx:Label id="criticite" width="20" fontWeight="bold" text=""/> > > </mx:HBox> >

