7 Replies Latest reply on Apr 20, 2010 2:33 PM by Flex harUI

    Scaling UI Components

    alice_data Level 1

      Hi,

      I wonder if anyone has tried doing this. I have several coordinates  here as here:

      <region name="triangle">
      <perimeter>
      <x>8</x><y>10</y>
      <x>2</x><y>10</y>
      <x>2</x><y>5</y>
      <x>8</x><y>5</y>
      </perimeter>
      </region>
      <region name="rect">
      <perimeter>
      <x>30</x><y>1</y>
      <x>20</x><y>1</y>
      <x>20</x><y>2</y>
      <x>30</x><y>2</y>
      </perimeter>
      </region>

      I am trying to use some simple way of finding out what the width and  height of the objects that I draw on the canvas. I call up the main app using this:

       

      drawThematicMap.setCanvas(100,100,300,500);             
         drawThematicMap.draw(regions);

       

      This is what is in the drawThematicMap class:

       

          public var canvas:Canvas;
             
              public function setCanvas(x:Number,y:Number,width:Number,height:Number):void{
             
                  canvas.setActualSize(width,height);
                  canvas.x = x;
                  canvas.y = y;  
              }
              public function draw(arr:Array):void{
                 
               regions = arr;    
               var shape:UIComponent;
                       var gr:Graphics;
                       var coords:Array;
              
                   for (var s:String in regions) {
                      trace("\n" + s);
                     
                      shape = new UIComponent();  
                      gr = shape.graphics;
                      gr.lineStyle(3);//Define line style                   
                     
                      coords = regions[s];
                      gr.moveTo(coords[0],coords[1]);
                     
                   for (var i:int = 2; i < coords.length; i += 2) gr.lineTo(coords[i],coords[i + 1]);                  
                       gr.lineTo(coords[0],coords[1]);  
                       gr.endFill(); //Put this in if there is a color
                       canvas.addChild(shape);  
                 }   
            }

       

      I am trying to  use the information so I can possibly use it for rescaling the image so I  don't have to calculate all my coordinates one by one.

      Is there a simple way to do this?

       

       

      Thanks for your help.

       

      Alice