Search code examples
flashactionscript-3stage

Detecting a movieclip has been Flipped horizontally on the stage in as3


If two movie clips instances of the same movieclip are placed on the stage and one is flipped horizontally in Flash.. Is there a way I can detect which one has been flipped horizontally in code? ScaleX seems to remain unchanged.

The MovieClip has been flipped horizontally using the Flash UI (Edit->Flip Horizontal), not via code.


Solution

  • Try:

    function isFlippedHorizontally( obj:DisplayObject ):Boolean
    {
        return obj.transform.matrix.a / obj.scaleX == -1;
    }
    
    trace( isFlippedHorizontally( yourObject ) );
    

    edit:
    I should have accounted for the scaleX of the object; adjusted now.

    Alternatively:

    import fl.motion.MatrixTransformer;
    
    function isFlippedHorizontally( obj:DisplayObject ):Boolean
    {
        return MatrixTransformer.getSkewYRadians( obj.transform.matrix ) / Math.PI == 1;
    }
    
    trace( isFlippedHorizontally( yourObject ) );
    

    edit:
    Last example accidentally had calculation for vertically flipped in stead of horizontally flipped.