9 Replies Latest reply on Feb 18, 2010 8:45 PM by Vikram_S

    how to Flip the image

    vineet osho

      Hello guys

                     is there any way in flex to flip the image.i need to flip the image and then paste it on some other location.

      so plz tell me anyway to flip the image.so that i can paste it to some another location


      Waiting for your response

       

      Thanks in advance

        • 1. Re: how to Flip the image
          Vikram_S Level 2

          HI,

           

          var image:Image;

          var m:Matrix = new Matrix();
          m.scale(-1, 0); // flip horizontal assuming that scaleX is currently 1
          image.transform.matrix = m;
          1 person found this helpful
          • 2. Re: how to Flip the image
            vineet osho Level 1

            Thanks vikram for your concern.

            but this technique is not working in my case.

            instead of flipping it eliminate the image.is there any other way out for this?.

            • 3. Re: how to Flip the image
              Vikram_S Level 2

              Hi,

               

              Add this line

              m.translate(image.width, 0); 

              Thanks,
              Vikram
              1 person found this helpful
              • 4. Re: how to Flip the image
                vineet osho Level 1

                hi vikram as u directed i put that code in my application but still it eliminat the image from stage.

                here is code which i write in flip button clicked.

                here img is image id which i took through mxml tag and provided source within same tag.

                 

                 

                var m:Matrix=new Matrix();
                m.scale(-1, 0);
                img.transform.matrix=m;
                m.translate(img.width, 0);

                • 5. Re: how to Flip the image
                  Vikram_S Level 2

                  Hi,

                  Try this

                                 var originalX:Number = img.x+img.width;
                                  img.scaleX = -1;
                                  img.x = originalX;

                  • 6. Re: how to Flip the image
                    vineet osho Level 1

                    Vikram

                    i already try this code.this code work only first time means only flips once  after that it simply shift the image with the diffrence of imagewidth+X.

                    • 7. Re: how to Flip the image
                      Vikram_S Level 2

                      Dud this should work

                       

                                   var displayObject:Image = image;
                                  var centerPoint:Point = new Point (displayObject.width/2,displayObject.height/2);
                                  var centerPointTransformed:Point = displayObject.localToGlobal(centerPoint);
                                 
                                  //strores the center wrt to global co-ord system
                                  centerPointTransformed = displayObject.parent.globalToLocal(centerPointTransformed);
                                  //rotate image                 
                                  var m:Matrix = displayObject.transform.matrix;
                                  m.a = sx;
                                  m.d = sy;
                                  displayObject.transform.matrix = m;
                                 
                                  var centerPointAfterRotation:Point = displayObject.localToGlobal(centerPoint);
                                 
                                  //stores the center after rotation wrt to global co-ord system
                                  centerPointAfterRotation = displayObject.parent.globalToLocal(centerPointAfterRotation);
                                  //calculate the delta i.e. change in center-x, center-y of of object when rotated wrt origin (of local-co-ord system)
                                  var dx:Number = centerPointAfterRotation.x - centerPointTransformed.x;
                                  var dy:Number = centerPointAfterRotation.y - centerPointTransformed.y;
                                 
                                  //shift the object to make rotation appear wrt center (of it's local co-ord system).
                                  displayObject.x -= dx;
                                  displayObject.y -= dy;

                       

                      Thanks,

                      Vikram

                      • 8. Re: how to Flip the image
                        vineet osho Level 1

                        Dear quiet complex and lengthy code.

                        can u plz tell me what are sx & sy :-

                         

                        m.a = sx;
                        m.d = sy;

                         

                        my compiler throw error on these line.Bcoz these two variables are unknown

                        • 9. Re: how to Flip the image
                          Vikram_S Level 2

                          Hi

                          sorry, copied non edited code.

                          Let me simpliefied code for you

                           

                          /*call this function*/

                          flipImage(img,-1,1);

                           

                          // function  flip image from center which you may expect

                           

                                     public static function flipImage(image:Image,sx:Number,sy:Number):void{
                                          var displayObject:Image = image;
                                          var centerPoint:Point = new Point (displayObject.width/2,displayObject.height/2);
                                          var centerPointTransformed:Point = displayObject.localToGlobal(centerPoint);
                                         
                                          //strores the center wrt to global co-ord system
                                          centerPointTransformed = displayObject.parent.globalToLocal(centerPointTransformed);
                                          //rotate image                 
                                          var m:Matrix = displayObject.transform.matrix;
                                          m.scale(sx,sy);
                                          displayObject.transform.matrix = m;
                                         
                                          var centerPointAfterRotation:Point = displayObject.localToGlobal(centerPoint);
                                         
                                          //stores the center after rotation wrt to global co-ord system
                                          centerPointAfterRotation = displayObject.parent.globalToLocal(centerPointAfterRotation);
                                          //calculate the delta i.e. change in center-x, center-y of of object when rotated wrt origin (of local-co-ord system)
                                          var dx:Number = centerPointAfterRotation.x - centerPointTransformed.x;
                                          var dy:Number = centerPointAfterRotation.y - centerPointTransformed.y;
                                         
                                          //shift the object to make rotation appear wrt center (of it's local co-ord system).
                                          displayObject.x -= dx;
                                          displayObject.y -= dy; 
                                      }