4 Replies Latest reply on Jan 22, 2010 8:36 PM by Gregory Lafrance

    problem of previous highlighting capturing

    venkateshk

      Please help me

      The following is my code

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
           backgroundColor="white" creationComplete="cc()">
          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import mx.controls.Label;
                  import mx.containers.Box;
                  private var box:Box;
                  private var lab:Label;
                   
                  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");
                          lab = new Label();
                          lab.text = "A"+j;
                          box.addChild(lab);
                          hb1.addChild(box);
                      }
                       for(i=25,j=1;i<=hb2.width;i=i+25,j++)
                      {
                          box = new Box();
                          box.width=25;
                          box.height = hb2.height;
                          box.setStyle("borderStyle","solid");
                          box.setStyle("borderColor","black");
                          box.setStyle("verticalAlign","middle");
                          box.setStyle("horizontalAlign","center");
                          lab = new Label();
                          lab.text = "B"+j;
                          box.addChild(lab);
                          hb2.addChild(box);
                      }
                       for(i=25,j=1;i<=hb3.height;i=i+25,j++)
                      {
                          box = new Box();
                          box.width=hb3.width;
                          box.height = 25;
                          box.setStyle("borderStyle","solid");
                          box.setStyle("borderColor","black");
                          box.setStyle("verticalAlign","middle");
                          box.setStyle("horizontalAlign","center");
                          lab = new Label();
                          lab.text = "C"+j;
                          box.addChild(lab);
                          hb3.addChild(box);
                      }
                      for(i=25,j=1;i<=hb4.width;i=i+25,j++)
                      {
                          box = new Box();
                          box.width=25;
                          box.height = hb4.height;
                          box.setStyle("borderStyle","solid");
                          box.setStyle("borderColor","black");
                          box.setStyle("verticalAlign","middle");
                          box.setStyle("horizontalAlign","center");
                          lab = new Label();
                          lab.text = "D"+j;
                          lab.setStyle("fontFamily","Arial");
                          lab.rotation = 40;
                          box.addChild(lab);
                          hb4.addChild(box);
                      }
                      for(i=25,j=1;i<=hb5.width;i=i+25,j++)
                      {
                          box = new Box();
                          box.width=25;
                          box.height = hb5.height;
                          box.setStyle("borderStyle","solid");
                          box.setStyle("borderColor","black");
                          box.setStyle("verticalAlign","middle");
                          box.setStyle("horizontalAlign","center");
                          lab = new Label();
                          lab.text = "E"+j;
                          box.addChild(lab);
                          hb5.addChild(box);
                      }   
                  }
                  private function proceedCall():void
                  {
                      var start:uint;
                      var end:uint;
                      var boxLbl:String;
                      var num:uint;
                      var box1:Box;
                      var obj:Object;
                     
                      if(combo1.selectedItem=='A' && tiFrom.text!="" && tiTo.text!=""){
                      start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                      end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                      for each(box1 in hb1.getChildren()){
                        boxLbl = "";
                        for each(obj in box1.getChildren()){
                          if(obj is Label){
                            boxLbl = obj.text;                   
                            num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                     
                            if(num >= start && num <= end){
                              box1.setStyle("backgroundColor", 0x00FF00);               
                            }else{
                              box1.setStyle("backgroundColor", null);                       
                            }
                          }
                        }
                      }
                    }
                   
                   
                      if(combo1.selectedItem=='B' && tiFrom.text!="" && tiTo.text!=""){
                      start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                      end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                      for each(box1 in hb2.getChildren()){
                        boxLbl = "";
                        for each(obj in box1.getChildren()){
                          if(obj is Label){
                            boxLbl = obj.text;                   
                            num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                     
                            if(num >= start && num <= end){
                              box1.setStyle("backgroundColor", 0x00FF00);               
                            }else{
                              box1.setStyle("backgroundColor", null);                       
                            }
                          }
                        }
                      }
                    }
                   
                   
                    if(combo1.selectedItem=='C' && tiFrom.text!="" && tiTo.text!=""){
                      start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                      end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                      for each(box1 in hb3.getChildren()){
                        boxLbl = "";
                        for each(obj in box1.getChildren()){
                          if(obj is Label){
                            boxLbl = obj.text;                   
                            num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                     
                            if(num >= start && num <= end){
                              box1.setStyle("backgroundColor", 0x00FF00);               
                            }else{
                              box1.setStyle("backgroundColor", null);                       
                            }
                          }
                        }
                      }
                    }
                   
                   
                    if(combo1.selectedItem=='D' && tiFrom.text!="" && tiTo.text!=""){
                      start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                      end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                      for each(box1 in hb4.getChildren()){
                        boxLbl = "";
                        for each(obj in box1.getChildren()){
                          if(obj is Label){
                            boxLbl = obj.text;                   
                            num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                     
                            if(num >= start && num <= end){
                              box1.setStyle("backgroundColor", 0x00FF00);               
                            }else{
                              box1.setStyle("backgroundColor", null);                       
                            }
                          }
                        }
                      }
                    }
                   
                   
                    if(combo1.selectedItem=='E' && tiFrom.text!="" && tiTo.text!=""){
                      start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                      end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                      for each(box1 in hb5.getChildren()){
                        boxLbl = "";
                        for each(obj in box1.getChildren()){
                          if(obj is Label){
                            boxLbl = obj.text;                   
                            num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                     
                            if(num >= start && num <= end){
                              box1.setStyle("backgroundColor", 0x00FF00);               
                            }else{
                              box1.setStyle("backgroundColor", null);                       
                            }
                          }
                        }
                      }
                    } 
                   
                  }
              ]]>
          </mx:Script>
          <mx:HBox id="hb1" width="1000" height="70" x="10" y="40" horizontalGap="0"/>
          <mx:HBox id="hb2" width="1000" height="60" x="10" y="120" horizontalGap="0"/>
          <mx:VBox id="hb3" width="80" height="250" x="10" y="200" verticalGap="0"/>
          <mx:HBox id="hb4" width="250" height="50" x="600" y="200" horizontalGap="0" rotation="40"/>
          <mx:HBox id="hb5" width="250" height="50" x="550" y="270" horizontalGap="0" rotation="40"/>
          <mx:HBox x="200" y="500" paddingBottom="0" paddingTop="0">
              <mx:Label text="Select Region :" fontSize="15" fontWeight="bold"/>
              <mx:ComboBox dataProvider="{['A','B','C','D','E']}" id="combo1"/>
              <mx:HBox horizontalGap="0">
                  <mx:Label text="From :" fontSize="15" fontWeight="bold" paddingRight="0"/>
                  <mx:TextInput width="35" id="tiFrom"/>
              </mx:HBox>
              <mx:HBox horizontalGap="0">
                  <mx:Label text="To :" fontSize="15" fontWeight="bold" paddingRight="0"/>
                  <mx:TextInput width="35" id="tiTo"/>
              </mx:HBox>
              <mx:Button label="Proceed" click="proceedCall()"/>
          </mx:HBox>
      </mx:Application>

      if I selected 'A' from Combobox and enter 1 in tiFrom and 5 in tiTo the corresponding boxes(i.e A1-A5) are highlighted with color

      it's fine but again if i want to enter another values for 'A' previous highlighted boxes are unhighlighted and later entering values

      corresponding boxes are highlighted

        • 1. Re: problem of previous highlighting capturing
          Gregory Lafrance Level 6

          Here you go:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
               backgroundColor="white" creationComplete="cc()">
              <mx:Script>
                  <![CDATA[
                      import mx.controls.Alert;
                      import mx.controls.Label;
                      import mx.containers.Box;
                      private var box:Box;
                      private var lab:Label;
                        
                      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");
                              lab = new Label();
                              lab.text = "A"+j;
                              box.addChild(lab);
                              hb1.addChild(box);
                          }
                           for(i=25,j=1;i<=hb2.width;i=i+25,j++)
                          {
                              box = new Box();
                              box.width=25;
                              box.height = hb2.height;
                              box.setStyle("borderStyle","solid");
                              box.setStyle("borderColor","black");
                              box.setStyle("verticalAlign","middle");
                              box.setStyle("horizontalAlign","center");
                              lab = new Label();
                              lab.text = "B"+j;
                              box.addChild(lab);
                              hb2.addChild(box);
                          } 
                           for(i=25,j=1;i<=hb3.height;i=i+25,j++)
                          {
                              box = new Box();
                              box.width=hb3.width;
                              box.height = 25;
                              box.setStyle("borderStyle","solid");
                              box.setStyle("borderColor","black");
                              box.setStyle("verticalAlign","middle");
                              box.setStyle("horizontalAlign","center");
                              lab = new Label();
                              lab.text = "C"+j;
                              box.addChild(lab);
                              hb3.addChild(box);
                          } 
                          for(i=25,j=1;i<=hb4.width;i=i+25,j++)
                          {
                              box = new Box();
                              box.width=25;
                              box.height = hb4.height;
                              box.setStyle("borderStyle","solid");
                              box.setStyle("borderColor","black");
                              box.setStyle("verticalAlign","middle");
                              box.setStyle("horizontalAlign","center");
                              lab = new Label();
                              lab.text = "D"+j;
                              lab.setStyle("fontFamily","Arial");
                              lab.rotation = 40;
                              box.addChild(lab);
                              hb4.addChild(box);
                          } 
                          for(i=25,j=1;i<=hb5.width;i=i+25,j++)
                          {
                              box = new Box();
                              box.width=25;
                              box.height = hb5.height;
                              box.setStyle("borderStyle","solid");
                              box.setStyle("borderColor","black");
                              box.setStyle("verticalAlign","middle");
                              box.setStyle("horizontalAlign","center");
                              lab = new Label();
                              lab.text = "E"+j;
                              box.addChild(lab);
                              hb5.addChild(box);
                          }    
                      }
                      private function proceedCall():void
                      {
                          var start:uint;
                          var end:uint;
                          var boxLbl:String;
                          var num:uint;
                          var box1:Box;
                          var obj:Object;
                          
                          if(combo1.selectedItem=='A' && tiFrom.text!="" && tiTo.text!=""){
                          start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                          end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                          for each(box1 in hb1.getChildren()){
                            boxLbl = "";
                            for each(obj in box1.getChildren()){
                              if(obj is Label){
                                boxLbl = obj.text;                    
                                num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                if(num >= start && num <= end){
                                  box1.setStyle("backgroundColor", 0x00FF00);                
                                }
                              }
                            }
                          }
                        }
                        
                        
                          if(combo1.selectedItem=='B' && tiFrom.text!="" && tiTo.text!=""){
                          start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                          end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                          for each(box1 in hb2.getChildren()){
                            boxLbl = "";
                            for each(obj in box1.getChildren()){
                              if(obj is Label){
                                boxLbl = obj.text;                    
                                num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                if(num >= start && num <= end){
                                  box1.setStyle("backgroundColor", 0x00FF00);                
                                }
                              }
                            }
                          }
                        }
                        
                        
                        if(combo1.selectedItem=='C' && tiFrom.text!="" && tiTo.text!=""){
                          start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                          end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                          for each(box1 in hb3.getChildren()){
                            boxLbl = "";
                            for each(obj in box1.getChildren()){
                              if(obj is Label){
                                boxLbl = obj.text;                    
                                num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                if(num >= start && num <= end){
                                  box1.setStyle("backgroundColor", 0x00FF00);                
                                }
                              }
                            }
                          }
                        }
                        
                        
                        if(combo1.selectedItem=='D' && tiFrom.text!="" && tiTo.text!=""){
                          start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                          end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                          for each(box1 in hb4.getChildren()){
                            boxLbl = "";
                            for each(obj in box1.getChildren()){
                              if(obj is Label){
                                boxLbl = obj.text;                    
                                num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                if(num >= start && num <= end){
                                  box1.setStyle("backgroundColor", 0x00FF00);                
                                }
                              }
                            }
                          }
                        }
                        
                        
                        if(combo1.selectedItem=='E' && tiFrom.text!="" && tiTo.text!=""){
                          start = uint(tiFrom.text.substring(tiFrom.text.search(/\d+/)));
                          end = uint(tiTo.text.substring(tiTo.text.search(/\d+/)));
                          for each(box1 in hb5.getChildren()){
                            boxLbl = "";
                            for each(obj in box1.getChildren()){
                              if(obj is Label){
                                boxLbl = obj.text;                    
                                num = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                if(num >= start && num <= end){
                                  box1.setStyle("backgroundColor", 0x00FF00);                
                                }
                              }
                            }
                          }
                        }  
                        
                      }
                  ]]>
              </mx:Script>
              <mx:HBox id="hb1" width="1000" height="70" x="10" y="40" horizontalGap="0"/>
              <mx:HBox id="hb2" width="1000" height="60" x="10" y="120" horizontalGap="0"/>
              <mx:VBox id="hb3" width="80" height="250" x="10" y="200" verticalGap="0"/>
              <mx:HBox id="hb4" width="250" height="50" x="600" y="200" horizontalGap="0" rotation="40"/>
              <mx:HBox id="hb5" width="250" height="50" x="550" y="270" horizontalGap="0" rotation="40"/>
              <mx:HBox x="200" y="500" paddingBottom="0" paddingTop="0">
                  <mx:Label text="Select Region :" fontSize="15" fontWeight="bold"/>
                  <mx:ComboBox dataProvider="{['A','B','C','D','E']}" id="combo1"/>
                  <mx:HBox horizontalGap="0">
                      <mx:Label text="From :" fontSize="15" fontWeight="bold" paddingRight="0"/>
                      <mx:TextInput width="35" id="tiFrom"/>
                  </mx:HBox>
                  <mx:HBox horizontalGap="0">
                      <mx:Label text="To :" fontSize="15" fontWeight="bold" paddingRight="0"/>
                      <mx:TextInput width="35" id="tiTo"/>
                  </mx:HBox>
                  <mx:Button label="Proceed" click="proceedCall()"/>
              </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: problem of previous highlighting capturing
            Gregory Lafrance Level 6

            I made your code more efficient, though it is certainly more complex:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                 backgroundColor="white" creationComplete="cc()">
                <mx:Script>
                    <![CDATA[
                      import mx.core.Container;
                        import mx.controls.Alert;
                        import mx.controls.Label;
                        import mx.containers.Box;
                        
                        private var boxes:Array = [
                          {hbox: "hb1", label: "A", num: 25, font: null, rotation: 0, direction: "vertical"},
                          {hbox: "hb2", label: "B", num: 25, font: null, rotation: 0, direction: "vertical"},
                          {hbox: "hb3", label: "C", num: 25, font: null, rotation: 0, direction: "horizontal"},
                          {hbox: "hb4", label: "D", num: 25, font: "Arial", rotation: 40, direction: "vertical"},
                          {hbox: "hb5", label: "E", num: 25, font: "Arial", rotation: 40, direction: "vertical"}
                        ];
                        
                        private function getBox(boxHeightWidth:Number, boxLabel:String, 
                          num:uint, textFont:String=null, boxRotation:Number = 0,
                          direction:String="horizontal"):Box{
                          var box:Box = new Box();
                          if(direction == "horizontal"){
                            box.width=boxHeightWidth;
                            box.height=25;                
                          }else{
                            box.height=boxHeightWidth;
                            box.width=25;                
                          }
                          box.setStyle("borderStyle","solid");
                          box.setStyle("borderColor","black");
                          box.setStyle("verticalAlign","middle");
                          box.setStyle("horizontalAlign","center");
                          var lab:Label = new Label();
                          if(textFont != null){
                            lab.setStyle("fontFamily","Arial");                
                          }
                          if(boxRotation != 0){
                            lab.rotation = 40;                
                          }
                          lab = new Label();
                          lab.text = boxLabel+ String(num);
                          box.addChild(lab);
                          trace("label: " + lab.text);
                          trace("width: " + box.width);
                          trace("height: " + box.height);
                          trace("****************************************");
                          return box;                    
                        }
                          
                        private function cc():void{                
                          for each(var obj:Object in boxes){
                            var widthHeight:Number = obj.direction=="horizontal"?this[obj.hbox].width:this[obj.hbox].height;
                            for(var j:uint=1;j<=obj.num;j++){
                              this[obj.hbox].addChild(getBox(widthHeight, obj.label, 
                                j, obj.font, obj.rotation, obj.direction));
                            }
                          }
                        }
                        private function proceedCall():void
                        {
                          var container:Container;
                          switch(combo1.selectedItem){
                            case "A":
                              container = hb1;
                              break;
                            case "B":
                              container = hb2;
                              break;
                            case "C":
                              container = hb3;
                              break;
                            case "D":
                              container = hb4;
                              break;
                            case "E":
                              container = hb5;
                              break;
                          }
                            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 box1:Box in container.getChildren()){
                                var boxLbl:String = "";
                                for each(var obj:Object in box1.getChildren()){
                                  if(obj is Label){
                                    boxLbl = obj.text;                    
                                    var num:uint = uint(boxLbl.substring(boxLbl.search(/\d+/)));                      
                                    if(num >= start && num <= end){
                                      box1.setStyle("backgroundColor", 0x00FF00);                
                                    }
                                  }
                                }
                              }
                            }
                        }
                    ]]>
                </mx:Script>
                <mx:HBox id="hb1" width="1000" height="70" x="10" y="40" horizontalGap="0"
                  horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
                <mx:HBox id="hb2" width="1000" height="60" x="10" y="120" horizontalGap="0"
                  horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
                <mx:VBox id="hb3" width="80" height="250" x="10" y="200" verticalGap="0"
                  horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
                <mx:HBox id="hb4" width="250" height="50" x="600" y="200" horizontalGap="0" rotation="40"
                  horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
                <mx:HBox id="hb5" width="250" height="50" x="550" y="270" horizontalGap="0" rotation="40"
                  horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
                <mx:HBox x="200" y="500" paddingBottom="0" paddingTop="0">
                    <mx:Label text="Select Region :" fontSize="15" fontWeight="bold"/>
                    <mx:ComboBox dataProvider="{['A','B','C','D','E']}" id="combo1"
                      change="tiFrom.text='';tiTo.text='';"/>
                    <mx:HBox horizontalGap="0">
                        <mx:Label text="From :" fontSize="15" fontWeight="bold" paddingRight="0"/>
                        <mx:TextInput width="35" id="tiFrom"/>
                    </mx:HBox>
                    <mx:HBox horizontalGap="0">
                        <mx:Label text="To :" fontSize="15" fontWeight="bold" paddingRight="0"/>
                        <mx:TextInput width="35" id="tiTo"/>
                    </mx:HBox>
                    <mx:Button label="Proceed" click="proceedCall()"/>
                </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

            1 person found this helpful
            • 3. Re: problem of previous highlighting capturing
              venkateshk Level 1

              ThankQ very much for reply

              I found one problem here when i give a letter in tiFrom it's taking the 1st position as starting point to fill

              I want only numbers to give in the tiFrom and tiTo

              please rectify this problem

              • 4. Re: problem of previous highlighting capturing
                Gregory Lafrance Level 6

                That is a separate issue. Please mark this as answered by me and create a new post for the valildation.