2 Replies Latest reply on Feb 9, 2011 5:26 AM by BhaskerChari

    Set style in a Label control inside Repeater

    Flex Rock Level 1

      Hi,

                 I want to set the two styles for a label control inside a repeater. One is the default style and another one i need to change the style based on the selected value. Both should set at the same time. So based on the value it will set the styles to corresponding labels inside the repeater. Is it possible.

       

      thanks,

      Jayagopal.

        • 1. Re: Set style in a Label control inside Repeater
          BhaskerChari Level 4

          Your question is not very clear to me , can you elaborate on this please..:)

           

          What do you mean here when you say ... i need to change the style based on the selected value

          Thanks,

          Bhasker

           

          Message was edited by: BhaskerChari

          • 2. Re: Set style in a Label control inside Repeater
            BhaskerChari Level 4

            Hi Jayagopal.

             

            Hope this is what you need..firstly the default first label is selected and then when you click on any particular label this label  gets highlighted and the previous label gets deselected and unhighlighted...

             

            <?xml version="1.0"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:Script><![CDATA[
               import mx.controls.Label;
                 import mx.collections.ArrayCollection;

                 [Bindable]
                 private var _dataProvider:ArrayCollection = new ArrayCollection([
                             {label:"Video Quality Optimized (recommended)"},
                             {label:"480p (High)"},
                             {label:"360p (Med)"},
                             {label:"288p (Low)"}
                 ]);
              private var prevHighlightedItem:Label
             
              private function repeaterItemClickHandler(event:MouseEvent):void
                 {
                  var label:Label = event.currentTarget as Label;
                  label.setStyle("fontWeight","bold");
                  prevHighlightedItem.setStyle("fontWeight","normal");
                  prevHighlightedItem = label;
                 }
                 private function onRepeatEnd():void
                 {
                  prevHighlightedItem = container.getChildAt(0) as Label;
                  prevHighlightedItem.setStyle("fontWeight","bold");
                 }

              ]]></mx:Script>

            <mx:VBox id="container" verticalGap="0" width="300" backgroundColor="#000000" verticalScrollPolicy="off" horizontalScrollPolicy="off">
              <mx:Repeater id="rptComp" repeatEnd="onRepeatEnd()" dataProvider="{_dataProvider}" recycleChildren="true">
               <mx:Label click="repeaterItemClickHandler(event)" text="{rptComp.currentItem.label}" color="white" fontSize="13" />
               <mx:HRule width="100%" strokeColor="white" visible="{rptComp.currentIndex != _dataProvider.length-1}" includeInLayout="{rptComp.currentIndex != _dataProvider.length-1}" />
              </mx:Repeater>
            </mx:VBox>

            </mx:Application>

             

             

             

            Thanks,

            Bhasker