开发者

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 Hor开发者_如何学运维izontal), not via code.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜