“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

As3 Flip Vertical and Flip Horizontal

Posted: June 11th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Code | 14 Comments »


14 Comments on “As3 Flip Vertical and Flip Horizontal”

  1. 1 kevincao said at 4:59 pm on June 18th, 2008:

    Hi, Thank u for sharing. I’ve post it to my blog for reference and send a trackback to you.
    http://kevincao.com/2008/06/17/as3-flip-vertical-and-flip-horizontal

  2. 2 piggy said at 3:58 pm on July 2nd, 2008:

    Very nice example, but i have trouble:
    when i’m trying to flip object with text (i.e. label, button) I don’t see text after flipping.
    After appplying flip once more, text appear back.
    Any suggestions ?

  3. 3 piggy said at 4:20 pm on July 2nd, 2008:

    ah…
    sorry :)
    If you want to do something like flip with objects with text, you must use embed fonts.

  4. 4 Idoru said at 6:45 pm on July 2nd, 2008:

    Yes, otherwise the fonts aren’t eligible to be rasterized into bitmaps.

  5. 5 xleon said at 2:36 pm on August 15th, 2008:

    Hi, I´m not sure what your code does, but I think it´s easier like this:

    vertical:
    dsp.scaleY = -dsp.scaleY;

    horizontal:
    dsp.scaleX = -dsp.scaleX;

  6. 6 g said at 11:59 pm on August 18th, 2008:

    xleon,

    Your method doesn’t work with video, while the others do.

  7. 7 Michael said at 12:49 pm on August 27th, 2008:

    to switch back and forth, use this:

    function flipHorizontal(dsp:DisplayObject):void
    {
    var matrix:Matrix = dsp.transform.matrix;
    //matrix.a = -1;
    matrix.a *= -1;
    //matrix.tx = dsp.width + dsp.x;
    matrix.tx = -matrix.a * dsp.width + dsp.x;
    dsp.transform.matrix = matrix;
    }

    function flipVertical(dsp:DisplayObject):void
    {
    var matrix:Matrix = dsp.transform.matrix;
    //matrix.d = -1;
    matrix.d *= -1;
    matrix.ty = -matrix.d * dsp.height + dsp.y;
    //matrix.ty = dsp.height + dsp.y;
    dsp.transform.matrix = matrix;
    }

  8. 8 Eric Brito said at 7:34 pm on October 24th, 2008:

    Does anyone know how the Michael’s code woulde be if the image had a bigger or smaller scale and a rotation angle?

  9. 9 gm said at 6:19 am on March 5th, 2009:

    Can anybody help in maintaining the same position while flipping.

  10. 10 underblob » AS3 Flip Horizontal/Vertical said at 7:21 pm on February 16th, 2010:

    [...] dreaminginflash.com Comments (0) [...]

  11. 11 Danny said at 12:50 pm on May 6th, 2010:

    Fantastic!!

    Thank you very much :)

  12. 12 davidpaulrosser said at 11:23 am on June 27th, 2010:

    Thanks, just what I was looking for!

  13. 13 Giovanni said at 12:55 am on December 15th, 2010:

    Thanks! It worked smoothly!

  14. 14 Salman Sohail said at 5:47 am on July 26th, 2011:

    Appriciate your work…Please use this for toggle flip :

    public function flipHorizontal(event:Event):void
    {
    var matrix:Matrix = selectedGraphic.transform.matrix;
    trace(matrix.a);
    if(matrix.a == 1)
    {
    matrix.a=-1;
    }
    else
    {
    matrix.a=1;
    }

    selectedGraphic.transform.matrix=matrix;
    }

    public function flipVertical(event:Event):void
    {

    var matrix:Matrix = selectedGraphic.transform.matrix;
    if(matrix.d == 1)
    {
    matrix.d=-1;
    }
    else
    {
    matrix.d=1;
    }

    selectedGraphic.transform.matrix=matrix;
    }


Leave a Reply