6 Replies Latest reply on Jun 27, 2011 8:07 AM by Flex harUI

    problem with transform.matrix


      hello everyone,


      my problem is that i have created a custom shape class which inherit UIComponent. now if i transform the shape object i am unable to get the new width and height value.




      var shape:Shape = new Shape();

      shape.type = Shape.TRIANGLE.

      shape.width = 100;

      shape.height = 100;


      var mat:Matrix = new Matrix();

      mat.scale(1.5, 1.5);

      shape.transform.matrix = mat;



      trace("scaleX: "+shape.scaleX+", width: "+shape.width+"\nscaleY:"+shape.scaleY+", height: "+shape.height);


      ///// scale value tracing 1 instead of 1.5, and 100 instead of 150 for height and width.


      the problem also persists if i use canvas instead of shape. it will be realy helpfull if someone will point me out what i am doing wrong




        • 1. Re: problem with transform.matrix
          alias19 Level 1

          on basis of above problem i have written a basic app in flex in which i have used a Sprite and a UIComponent, Sprite is working well but UIComponent is having a problem.





          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="
          http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"

             import mx.core.UIComponent;
             private var spt:UIComponent;
             private var spt2:Sprite;
             private function init():void{
              spt = new UIComponent();
               drawRect(0, 0, 100, 100);
              spt2 = new Sprite();
               drawRect(0, 0, 100, 100);
              spt2.x = 500;
             private function onChange():void{
              var mat:Matrix = new Matrix();
              mat.scale(scale.value, scale.value);
              spt.transform.matrix = mat;
              debug.text = "scaleX: "+spt.scaleX+", width: "+spt.width+"\nscaleY: "+spt.scaleY+", height: "+spt.height;
              var mat2:Matrix = new Matrix();
              mat2.tx = 500;
              mat2.scale(scale.value, scale.value);
              spt2.transform.matrix = mat2;
              debug.text = debug.text+"\nscaleX: "+spt2.scaleX+", width: "+spt2.width+"\nscaleY: "+spt2.scaleY+", height: "+spt2.height;

          <!--<mx:Canvas width="100" height="100" x="10" y="10" backgroundColor="#FFFFFF"
          <mx:Text x="10" y="502" id="debug"/>
          <mx:HSlider x="411" y="508" minimum="0.2" maximum="4" snapInterval="0.1" liveDragging="true"
              change="onChange()" id="scale"/>



          pls help me

          • 2. Re: problem with transform.matrix
            Flex harUI Adobe Employee

            In Flex 3, UIComponent doesn't support rotation.

            • 3. Re: problem with transform.matrix
              alias19 Level 1

              the rotation is working well. it is scale which is not working, Actually scale is also working it is the value which is not updating.

              • 4. Re: problem with transform.matrix
                PresidentCamacho Level 1

                Instead of:

                var mat:Matrix = new Matrix();




                var mat : Matrix = shape.transform.matrix.clone();


                Setting the width/height of the original sprite may have changed the transform matrix itself.

                • 5. Re: problem with transform.matrix
                  alias19 Level 1

                  I have also tried it, not working.


                  but can anyone tell will the width and height of a sprite changes if the sprite is rotated using transform.matrix?

                  i have found the way to get width and height of UIComponent when transform by its transform.matrix by using its mx_internal properties




                  var wd:Number = shape.mx_internal::$width;

                  var ht:Number = shape.mx_internal::$height;



                  but the width and height changes as it rotate. same for sprite also.

                  so, can i get the real width & height instead of it's bounding width and height?

                  • 6. Re: problem with transform.matrix
                    Flex harUI Adobe Employee

                    What I meant by not supporting rotation is that the properties won't report

                    what you expect and layout won't honor rotated things.  Things will appear



                    If you rotate a 100x100 UIComponent by 45 degrees, it's x and y should

                    change, but it is width and height will show 100x100.  Transform.pixelBounds

                    should show its true bounding box though.