2 Replies Latest reply on Jan 20, 2010 8:57 PM by venkateshk

    working on particular position

    venkateshk Level 1

      help me please

      my scenario is as follows

      I want to have a canvas with multiple rectangles

      and i want to fill particular rectangle with color and also remove the color from particular rectangle

      how to do it

      how to add the name  inside every rectangle

        • 1. Re: working on particular position
          archemedia Level 4

          It's not very clear to me what you are trying to do but I'll give it a try.

           

          If you add your rectangles dynamically, you can use the name property of the objects i.e.:

           

          var c:Canvas = new Canvas();

          c.name = "numberOne";

           

          afterwards, you can get to these objects by their name property i.e.:

           

          var canvasToLookFor:Canvas = container.getChildByName("numberOne");

           

          Does this help?

           

          Dany

          • 2. Re: working on particular position
            venkateshk Level 1

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                backgroundImage="images.jpeg" initialize="cc()">
                <mx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                        import mx.core.UIComponent;
                        import mx.controls.Alert;
                        private var unit:int = 15;
                        private var lastPos1: int=0;
                        private var lastPos2: int=0;
                        private var lastPos3: int=0;
                        private var lastPos4: int=0;
                        private var lastPos5: int=0;
                        private function btnCall(sa:String,units:String):void
                        {
                            var numUnits:int = parseInt(units);
                            if(sa == "A1")
                            {
                                      for(var i: int = 0; i < numUnits ; i++) {
                                          var lineThickness1:Number = 1;
                                          var lineColor1: Number = 0x000000;
                                          var lineAlpha1: Number = 1;
                                          var line1: UIComponent = new UIComponent();
                                          line1.graphics.lineStyle(lineThickness1, lineColor1, lineAlpha1);
                                          line1.graphics.beginFill(0xFFCC00, 1.0);
                                          line1.graphics.moveTo(((lastPos1+i) * unit), b1.y);
                                          line1.graphics.drawRect(((lastPos1+i) * unit)-1,-1, unit, b1.height);
                                          b1.addChild(line1);
                                       
                                    }
                                    lastPos1 = lastPos1+numUnits; 
                            }
                            else if(sa == "A2")
                            {
                                for(i= 0; i < numUnits ; i++) {
                                        var lineThickness2: Number = 1;
                                          var lineColor2: Number = 0x000000;
                                          var lineAlpha2: Number = 1;
                                          var line2: UIComponent = new UIComponent();
                                          line2.graphics.lineStyle(lineThickness2, lineColor2, lineAlpha2);
                                          line2.graphics.beginFill(0xFF0000, 1.0);
                                          line2.graphics.moveTo(b2.x,(lastPos2+i)*unit);
                                          line2.graphics.drawRect(-1,((lastPos2+i)*unit)-1, b2.width, unit);
                                          b2.addChild(line2); 
                                       
                                    }
                                    lastPos2 = lastPos2+numUnits;
                            }
                            else if(sa == "A3")
                            {
                                for(i= 0; i < numUnits ; i++) {
                                          var lineThickness3: Number = 1;
                                          var lineColor3: Number = 0x000000;
                                          var lineAlpha3: Number = 1;
                                          var line3: UIComponent = new UIComponent();
                                          line3.graphics.lineStyle(lineThickness3, lineColor3, lineAlpha3);
                                          line3.graphics.beginFill(0x00CC00, 1.0);
                                          line3.graphics.moveTo(((lastPos3+i) * unit), b3.y);
                                          line3.graphics.drawRect(((lastPos3+i) * unit)-1,-1, unit, b3.height);
                                          b3.addChild(line3);
                                    }
                                    lastPos3 = lastPos3+numUnits;
                            }
                            else if(sa == "A4")
                            {
                                for(i= 0; i < numUnits ; i++) {
                                          var lineThickness4: Number = 1;
                                          var lineColor4: Number = 0x000000;
                                          var lineAlpha4: Number = 1;
                                          var line4: UIComponent = new UIComponent();
                                          line4.graphics.lineStyle(lineThickness4, lineColor4, lineAlpha4);
                                          line4.graphics.beginFill(0xFFCCFF, 1.0);
                                          line4.graphics.moveTo(((lastPos4+i) * unit), b4.y);
                                          line4.graphics.drawRect(((lastPos4+i) * unit)-1,-1, unit, b4.height);
                                          b4.addChild(line4);
                                    }
                                    lastPos4 = lastPos4+numUnits;
                            }
                            else if(sa == "A5")
                            {
                                for(i= 0; i < numUnits ; i++) {
                                          var lineThickness5: Number = 1;
                                          var lineColor5: Number = 0x000000;
                                          var lineAlpha5: Number = 1;
                                          var line5: UIComponent = new UIComponent();
                                          line5.graphics.lineStyle(lineThickness5, lineColor5, lineAlpha5);
                                          line5.graphics.beginFill(0x0000FF, 1.0);
                                          line5.graphics.moveTo(((lastPos5+i) * unit), b5.y);
                                          line5.graphics.drawRect(((lastPos5+i) * unit)-1,-1, unit, b5.height);
                                          b5.addChild(line5);
                                    }
                                    lastPos5 = lastPos5+numUnits;
                            }
                        }
                       
                        private function cc():void
                        {
                            for(var i:int=b1.x;i<b1.x+b1.width;i=i+unit)
                            {
                                var line1:UIComponent = new UIComponent();
                                var lineThickness1:Number = 1;
                                var lineColor1:Number = 0x000000;
                                var lineAlpha1:Number = 1;
                                line1.graphics.lineStyle(lineThickness1,lineColor1,lineAlpha1);
                                line1.graphics.moveTo(i,b1.y);
                                line1.graphics.drawRect(i,b1.y,unit,b1.height);
                                this.addChild(line1);
                            } 
                             for(i=b2.y;i<b2.y+b2.height;i=i+unit)
                            {
                                var line2:UIComponent = new UIComponent();
                                var lineThickness2:Number = 1;
                                var lineColor2:Number = 0x000000;
                                var lineAlpha2:Number = 1;
                                line2.graphics.lineStyle(lineThickness2,lineColor2,lineAlpha2);
                                line2.graphics.moveTo(b2.x,i);
                                line2.graphics.drawRect(b2.x,i,b2.width,unit);
                                this.addChild(line2);
                            }
                            for(i=b3.x;i<b3.x+b3.width;i=i+unit)
                            {
                                var line3:UIComponent = new UIComponent();
                                var lineThickness3:Number = 1;
                                var lineColor3:Number = 0x000000;
                                var lineAlpha3:Number = 1;
                                line3.graphics.lineStyle(lineThickness3,lineColor3,lineAlpha3);
                                line3.graphics.moveTo(i,b3.y);
                                line3.graphics.drawRect(i,b3.y,unit,b3.height);
                                this.addChild(line3);
                            }
                            for(i = 0; i < b4.width; i = i + unit) {
                             var line4: UIComponent = new UIComponent();
                             var lineThickness4: Number = 1;
                             var lineColor4: Number = 0x000000;
                             var lineAlpha4: Number = 1;
                             line4.graphics.lineStyle(lineThickness4, lineColor4, lineAlpha4);
                             line4.graphics.moveTo(i, 0);
                             line4.graphics.drawRect(i,0,unit, b4.height - 1);
                             //Add line in canvas instead of main container
                             b4.addChild(line4);
                            }
                            for(i = 0; i < b5.width; i = i + unit) {
                             var line5: UIComponent = new UIComponent();
                             var lineThickness5: Number = 1;
                             var lineColor5: Number = 0x000000;
                             var lineAlpha5: Number = 1;
                             line5.graphics.lineStyle(lineThickness5, lineColor5, lineAlpha5);
                             line5.graphics.moveTo(i, 0);
                             line5.graphics.drawRect(i,0,unit, b5.height - 1);
                             //Add line in canvas instead of main container
                             b5.addChild(line5);
                            }    
                        }
                    ]]>
                </mx:Script>
                <mx:Canvas id="b1" x="10" y="10" height="40" width="300"/>
                <mx:Canvas id="b2" x="400" y="10" height="300" width="100"/>
                <mx:Canvas id="b3" x="10" y="50" height="40" width="300"/>
                <mx:Canvas id="b4" x="700" y="200" height="80" width="300" rotation="40"/>
                <mx:Canvas id="b5" x="620" y="280" height="80" width="300" rotation="40"/>
                <mx:HBox x="40" y="450">
                    <mx:Label text="Select Area :" fontWeight="bold" fontSize="15"/>
                    <mx:ComboBox id="combo1" dataProvider="{['A1','A2','A3','A4','A5']}"/>
                    <mx:Label text="Enter Units :" fontWeight="bold" fontSize="15"/>
                    <mx:TextInput id="tiUnits" width="50" maxChars="1"/>
                    <mx:Button id="btn" label="OK" click="btnCall(combo1.selectedItem.toString(),tiUnits.text);"/>
                </mx:HBox>
            </mx:Application>

            I did like the above but now i want this to highlight at particular position