0 Replies Latest reply on Jan 29, 2010 9:29 PM by venkateshk

    capturing with events

    venkateshk Level 1

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  xmlns:word="*" creationComplete="cc()" applicationComplete="service.dlist();"
          layout="absolute" backgroundColor="0xFFFFFF">
         
          <mx:RemoteObject id="service" destination="planSession">
              <mx:method name="dlist" result="resultHandler(event)" fault="Alert.show(event.fault.faultString)"/>
          </mx:RemoteObject>
         
          <mx:Script>
              <![CDATA[
                  import flash.sampler.getSampleCount;
                  import mx.controls.List;
                  import mx.events.ListEvent;
                  import mx.core.UIComponent;
                  import mx.rpc.events.ResultEvent;
                    import mx.core.Container;
                  import mx.controls.Alert;
                  import mx.controls.Label;
                  import mx.containers.Box;
                                  
                  [Embed(source='../assets/78skate.ttf',
                          fontName='myMyriadFont')]
                  private var font1:Class;
                 
                  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: "vertical"},
                    {hbox: "hb4", label: "D", num: 10, font: null, rotation: 0, direction: "vertical"},
                    {hbox: "hb5", label: "E", num: 10, font: null, rotation: 0, direction: "vertical"},
                    {hbox: "hb6", label: "F", num: 15, font: null, rotation: 0, direction: "horizontal"},
                    {hbox: "hb7", label: "G", num: 15, font: null, rotation: 0, direction: "horizontal"},
                  ];
                 
                  private function resultHandler(e:ResultEvent):void
                  {
                      var container1:Container;
                      for each(var dbObj:Object in e.result)
                      {
                          for each(var hbObj:Object in boxes)
                          {
                              switch(hbObj.hbox){
                                              case "hb1":
                                                container1 = hb1;
                                                break;
                                              case "hb2":
                                                container1 = hb2;
                                                break;
                                              case "hb3":
                                                container1 = hb3;
                                                break;
                                              case "hb4":
                                                container1 = hb4;
                                                break;
                                              case "hb5":
                                                container1 = hb5;
                                                break;
                                              case "hb6":
                                                container1 = hb6;
                                                break;
                                              case "hb6":
                                                container1 = hb7;
                                                break;
                              }
                              for each(var box1:Box in container1.getChildren()){
                                  for each(var lblObj:Object in box1.getChildren())
                                  {
                                      if(lblObj.text  == dbObj.name){
                                          box1.setStyle("backgroundColor", 0xFF0000);
                                      }
                                  }
                              }
                          }
                      }
                  }
                 
                  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();
                    lab.setStyle("fontFamily","myMyriadFont");
                    lab.text = boxLabel+ String(num);
                    lab.buttonMode = true;               
                    lab.useHandCursor = true;
                    lab.mouseChildren = false;
                    box.addChild(lab);
                    box.buttonMode = true;
                    box.addEventListener(MouseEvent.CLICK,comboSelectCall);
                    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.rotation, obj.direction));
                      }
                    }

                private function comboSelectCall(event:MouseEvent):void
                  {
                      var numberCargo:uint = uint(comboCargo.selectedItem);
                      var temp:uint = numberCargo;
                          if(event.currentTarget.getStyle("backgroundColor") == 0xFF0000)
                          {
                              Alert.show("oops.............","Alert");   
                          }
                          else
                          {
                              var ind:uint = event.currentTarget.parent.getChildIndex(event.currentTarget);
                              var current:uint = 1;
                             
                              for(var index:uint = ind; event.currentTarget.parent.getChildAt(index).getStyle("backgroundColor") != 0xFF0000 && current <= numberCargo;index++,current++)
                              {
                                  temp--;
                                  event.currentTarget.parent.getChildAt(index).setStyle("backgroundColor",0x00FF00);
                              }
                         }
                      }
                
              ]]>
          </mx:Script>

      <mx:HBox id="hb1" width="100%" height="50" x="10" y="40" horizontalGap="1"
            horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
          <mx:HBox id="hb2" width="70%" height="50" x="10" y="66" horizontalGap="1"
            horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
          <mx:HBox id="hb3" width="70%" height="50" x="10" y="92" horizontalGap="1"
            horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
          <mx:VBox x="600" y="180" rotation="40" verticalGap="-24">
              <mx:HBox id="hb4" width="510" height="50" horizontalGap="1"
                horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
              <mx:HBox id="hb5" width="510" height="50" horizontalGap="1"
                horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
          </mx:VBox>
          <mx:VBox id="hb6" width="50" height="500" x="190" y="140" verticalGap="1"
              horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
          <mx:VBox id="hb7" width="50" height="500" x="241" y="140" verticalGap="1"
              horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
          <mx:HBox x="200" y="610" paddingBottom="0" paddingTop="0">

      <mx:Label text="No.of Cargos :" fontSize="15" fontWeight="bold"/>
              <mx:ComboBox id="comboCargo" dataProvider="{['1','2','3','4','5','6','7','8','9','10']}"/>
          </mx:HBox>
      </mx:Application>

      This application getting the values from database and highlight them with red color

      Now I want to select a value from combobox

      then if i click on any box checking need to be done whether there is a chance or not based on the color

      it's working fine if i select 8 in combobox then I choose 4 from A

      and the remaining are 4 the problem here is how do i call the action listener on other boxes to use this 4 values to fill

      Plese.. help me