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

扶醉桌前 提交于 2019-12-07 11:56:46

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7577262/detecting-a-movieclip-has-been-flipped-horizontally-on-the-stage-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!