5 Replies Latest reply on Jan 22, 2010 8:59 AM by Gregory Lafrance

    From to To highlighting

    venkateshk Level 1

      Please..... help me

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
           backgroundColor="silver" creationComplete="cc()">

      <mx:Script>
              <![CDATA[

      private function cc():void{               
                       for(var i:int=25,j:int=1;i<=hb1.width;i=i+25,j++)
                      {
                          box = new Box();
                          box.width=25;
                          box.height = hb1.height;
                          box.setStyle("borderStyle","solid");
                          box.setStyle("borderColor","black");
                          box.setStyle("verticalAlign","middle");
                          box.setStyle("horizontalAlign","center");
                          box.id = "A"+j;
                          lab = new Label();
                          lab.text = "A"+j;
                          box.addChild(lab);
                          box.addEventListener(MouseEvent.CLICK,onMouseClick);
                          hb1.addChild(box);
                      }

      }

      private function onMouseClick(event:MouseEvent):void
                  {
                      if(event.currentTarget.getStyle("backgroundColor") != 0xFF0000){
                          event.currentTarget.setStyle("backgroundColor", 0xFF0000);               
                        }else{
                          event.currentTarget.setStyle("backgroundColor", null);
                        }
                  }

           ]]>
      </mx:Script>

      <mx:HBox id="hb1" width="1000" height="70" x="10" y="40" horizontalGap="0"/>

      <mx:HBox x="200" y="500" paddingBottom="0" paddingTop="0">
              <mx:Label text="From :" paddingTop="0" fontWeight="bold" fontSize="20"/>
              <mx:TextInput width="35" id="tiFrom"/>
              <mx:Spacer width="18"/>
              <mx:Label text="To :" fontWeight="bold" fontSize="20"/>
              <mx:TextInput width="35" id="tiTo"/>
              <mx:Button label="Proceed"/>
          </mx:HBox>

      </mx:Application>

      The above application gives HBox filled with multiple Boxes and each box has a label inside it i.e A1,A2,................A40

      and when i click on particular box it is highlighting with color if it is not filled with color it's well

      and now i want that From to To highlighting

      i.e if i give A5 in tiFrom and A10 in tiTo and clicking on Proceed button then I want that the boxes A5,A6,A7,A8,A9,A10 to be highlighted

        • 1. Re: From to To highlighting
          Gregory Lafrance Level 6

          This code solves your problem:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
               backgroundColor="silver" creationComplete="cc()">
          <mx:Script>
                  <![CDATA[
                    import mx.controls.Label;
                    import mx.containers.Box;
          private function cc():void{                
                           for(var i:int=25,j:int=1;i<=hb1.width;i=i+25,j++)
                          {
                              
                              var box:Box = new Box();
                              box.width=25;
                              box.height = hb1.height;
                              box.setStyle("borderStyle","solid");
                              box.setStyle("borderColor","black");
                              box.setStyle("verticalAlign","middle");
                              box.setStyle("horizontalAlign","center");
                              box.id = "A"+j;
                              var lab:Label = new Label();
                              lab.text = "A"+j;
                              box.addChild(lab);
                              box.addEventListener(MouseEvent.CLICK,onMouseClick);
                              hb1.addChild(box);
                          }
          }
          private function onMouseClick(event:MouseEvent):void
                      {
                          if(event.currentTarget.getStyle("backgroundColor") != 0xFF0000){
                              event.currentTarget.setStyle("backgroundColor", 0xFF0000);                
                            }else{
                              event.currentTarget.setStyle("backgroundColor", null);
                            }
                      }
          private function changeOneBG(disObj:Object):void{
            
          }
                      
                      private function setHighlightRange():void{
                        if(tiFrom.text!="" && tiTo.text!=""){
                          var start:uint = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                          var end:uint = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                          for each(var box:Box in hb1.getChildren()){
                            var boxLbl:String = "";
                            for each(var obj:Object in box.getChildren()){
                              if(obj is Label){
                                boxLbl = obj.text;                    
                                var num:uint = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                if(num >= start && num <= end){
                                  box.setStyle("backgroundColor", 0xFF0000);                
                                }else{
                                  box.setStyle("backgroundColor", null);                        
                                }
                              }
                            }
                          }
                        }
                      }
               ]]>
          </mx:Script>
          <mx:HBox id="hb1" width="1000" height="70" x="10" y="40" horizontalGap="0"/>
          <mx:HBox x="200" y="500" paddingBottom="0" paddingTop="0">
                  <mx:Label text="From :" paddingTop="0" fontWeight="bold" fontSize="20"/>
                  <mx:TextInput width="35" id="tiFrom"/>
                  <mx:Spacer width="18"/>
                  <mx:Label text="To :" fontWeight="bold" fontSize="20"/>
                  <mx:TextInput width="35" id="tiTo"/>
                  <mx:Button label="Proceed" click="setHighlightRange();"/>
              </mx:HBox>
          </mx:Application>
          
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          • 2. Re: From to To highlighting
            venkateshk Level 1

            ThankQ very much

            May I keep in touch with u?

            • 3. Re: From to To highlighting
              venkateshk Level 1

              It's working

              but even i give just 1 to 10 it's taking ok

              what I want is that

              earlier I have one HBox in that i have multiple boxes ok fine

              if I have multiple HBoxes named as A,B,C  etc all contain multiple Boxes

              I will add one combo box in that I have A,B,C

              then I can select anyone of the A,B,C from combo box and i can enter the from,to values then corresponding boxes need to be fill in that selected HBox

              <mx:HBox x="200" y="500" paddingBottom="0" paddingTop="0">
                      <mx:ComboBox dataProvider="{['A','B','C']}"/>
                      <mx:Label text="From :" paddingTop="0" fontWeight="bold" fontSize="20"/>
                      <mx:TextInput width="35" id="tiFrom"/>
                      <mx:Spacer width="18"/>
                      <mx:Label text="To :" fontWeight="bold" fontSize="20"/>
                      <mx:TextInput width="35" id="tiTo"/>
                      <mx:Button label="Proceed" click="setHighlightRange();"/>
                  </mx:HBox>

               

              Please help me

              • 4. Re: From to To highlighting
                venkateshk Level 1

                it's working fine

                but at second time when i give another values previous highlighted boxes are unhighlighted and later given box values are highlighted

                i need the previous highlighted boxes also to be highlighted when i give another new values

                please................ give the solution

                • 5. Re: From to To highlighting
                  Gregory Lafrance Level 6

                  I responded to your other post to solve the problem of the previously highlighted boxes becoming unhighlighted.

                   

                  I'm available for contract work. For non-paying questions, its best to post to this forum as you'll get more responses, usually.