3

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.

Marty
  • 39,033
  • 19
  • 93
  • 162
prettymuchbryce
  • 131
  • 1
  • 9
  • How was the MovieClip flipped in the first place? – sberry Sep 28 '11 at 01:15
  • Sorry I should have been more specific. There is a parent clip that is linked in the library of the FLA. It's exported as a SWC and this is what is accessed from the code. The code adds this linked parent clip to it's stage. Within the parent clip there are two child clips that are placed within it from the FLash IDE. One is flipped (Edit>Flip horizontally) and the other is not. I can't figure out how to discern via code which one was flipped. – prettymuchbryce Sep 28 '11 at 01:27

2 Answers2

6

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.

Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106
  • If the object has been both flipped and scaled, is it correct to check `obj.transform.matrix.a / obj.scaleX < 0;` instead? – James Webster Jan 31 '12 at 10:01
0

I like fireeyedoy's solution more for it's compactness and simplicity but you can also do it with some bitmapdata comparison:

var bmd1:BitmapData = new BitmapData(mc1.width, mc1.height);
var bmd2:BitmapData = new BitmapData(mc2.width, mc2.height);
var cbmd1:BitmapData = new BitmapData(mc1.width, mc1.height);
var cbmd2:BitmapData = new BitmapData(mc2.width, mc2.height);

var cmatrix1:Matrix = new Matrix();
var cmatrix2:Matrix = new Matrix();

cmatrix1.tx = -mc1.x;
cmatrix1.ty = -mc1.y;

cmatrix2.tx = -mc2.x;
cmatrix2.ty = -mc2.y;

bmd1.draw(mc1);
bmd2.draw(mc2);

cbmd1.draw(this, cmatrix1);
cbmd2.draw(this, cmatrix2);


if(cbmd1.compare(bmd1))
{
    trace("mc1 is flipped!");
}
else if(cbmd2.compare(bmd1))
{
    trace("mc2 is flipped!");
}

This is assuming that your movieclips are top-left aligned. If not then you will have to add the appropriate tx and ty values in the matrix while drawing them.

Marty
  • 39,033
  • 19
  • 93
  • 162
localhost
  • 169
  • 6