Detecting a movieclip has been Flipped horizontall

2019-05-16 16:34发布

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.

2条回答
可以哭但决不认输i
2楼-- · 2019-05-16 17:06

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.

查看更多
Lonely孤独者°
3楼-- · 2019-05-16 17:24

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.

查看更多
登录 后发表回答