Flip Horizontal Vertical Display Object MovieClip Flash Action Script
Hi, Today i came across a problem while using code from snipplr article for Flipping Display Objects and MovieClip in Flash Action Script 3. Problem was i was using a button to flip the movieclip horizontal and vertical. If i clicked the button twice it use to change its location. I have tweak the code to check if the movie clip is already mirrored or flipped horizontal or vertically and inverse the previous effect.
Flipping or Mirror Movie Clip and display object is a common requirement these days. Flash action script 3 geom.matrix class has solved most of the problems. Though its a bit tricky to use them. Any further questions let me know. Thank you all for supporting the blog.
Here Goes the code to flip Mirror action script 3 display objects and movie clips
function flipHorizontal(dsp:DisplayObject):void
{
var matrix:Matrix = dsp.transform.matrix;
matrix.transformPoint(new Point(dsp.width/2,dsp.height/2));
if(matrix.a>0){
matrix.a=-1*matrix.a;
matrix.tx=dsp.width+dsp.x;
}
else
{
matrix.a=-1*matrix.a;
matrix.tx=dsp.x-dsp.width;
}
dsp.transform.matrix=matrix;
}
function flipVertical(dsp:DisplayObject):void
{
var matrix:Matrix = dsp.transform.matrix;
matrix.transformPoint(new Point(dsp.width/2,dsp.height/2));
if(matrix.d>0){
matrix.d=-1*matrix.d;
matrix.ty=dsp.y+dsp.height;
}
else
{
matrix.d=-1*matrix.d;
matrix.ty=dsp.y-dsp.height;
}
dsp.transform.matrix=matrix;
}
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.
Comments
how to use work this as?
[Reply]
Thanks for the solution.
[Reply]
Hi,
Thanks for the work your have contributed. Used it. But there is a problem when the object is rotated and then flipped. You get a distorted image(skewed).
I have used the senocular transform tool to scale and rotate. A solution to this problem will be appreciated very much.
Thanks in advance,
Muttappan
[Reply]
HI, Its strange i got stuck in the same problem .. I worked on it for some time and have found out the solution for that ….
what you need to do is when you create the object which you need to rotate in future .. make sure its X, and Y position are at the center that means .. The registration Point is at the center.
As in flash you cannt change the center point of the Movieclip we physically move the child object to -(width/2) and -(Height/2).
If you are clear here now here is the modified code that i used .
function flipHorizontal(dsp:DisplayObject):void
{
var matrix:Matrix = dsp.transform.matrix;
//matrix.transformPoint(new Point(dsp.width/2,dsp.height/2));
var rot:Number = MatrixTransformer.getRotation(matrix);
trace(rot);
//MatrixTransformer.rotateAroundExternalPoint(matrix,dsp.x+(dsp.width/2),dsp.y+(dsp.height/2),20);
//matrix.rotate((-1*rot));
MatrixTransformer.setRotation(matrix,0);
dsp.transform.matrix=matrix;
matrix.d=-1*matrix.d;
//matrix.d=-1*matrix.d;
/*if(matrix.a>0){
matrix.a=-1*matrix.a;
//matrix.tx=dsp.x;
}
else
{
matrix.a=-1*matrix.a;
//matrix.tx=-dsp.x;
}*/
dsp.transform.matrix=matrix;
matrix = dsp.transform.matrix;
//rot = MatrixTransformer.getRotation(matrix);
trace(”second:”+rot);
MatrixTransformer.setRotation(matrix,(rot+180));
// matrix.rotate(rot+180);
dsp.transform.matrix=matrix;
}
function flipVertical(dsp:DisplayObject):void
{
var matrix:Matrix = dsp.transform.matrix;
var rot:Number = MatrixTransformer.getRotation(matrix);
//trace(rot);
//MatrixTransformer.rotateAroundExternalPoint(matrix,dsp.x+(dsp.width/2),dsp.y+(dsp.height/2),20);
MatrixTransformer.setRotation(matrix,0);
dsp.transform.matrix=matrix;
matrix.d=-1*matrix.d;
/*if(matrix.d>0){
matrix.d=-1*matrix.d;
//matrix.a=-1*matrix.a;
///matrix.b=-1*matrix.b;
//matrix.c=-1*matrix.c;
//matrix.ty=dsp.y+dsp.height;
//matrix.tx=dsp.x+dsp.width;
}
else
{
matrix.d=-1*matrix.d;
//matrix.a=-1*matrix.a;
//matrix.b=-1*matrix.b;
//matrix.c=-1*matrix.c;
//matrix.ty=dsp.y-dsp.height;
//matrix.tx=dsp.x-dsp.width;
}*/
dsp.transform.matrix=matrix;
MatrixTransformer.setRotation(matrix,rot);
dsp.transform.matrix=matrix;
}
[Reply]
There are some code withj comments i left it as it is just to make you see what experiments i did .. i hope thats help the ide ais that the vertical flip works fine but for horizantal i did a trick. Use the code Above and let me know
[Reply]
How to use this code? It would be better if you can post an example.
[Reply]
sanjaya kumar nanda Reply:
June 18th, 2009 at 10:25 pm
we want to create an animation same as the url home page banner animation.l please send me that code with examples.
[Reply]
Thank you!!!
You’re the best!
[Reply]
hi there..
i hope you doing well..
plz solve my problem transform the movie clip scripting send..
THANKS
MUHAMMAD KASHIF
[Reply]
nice job!
[Reply]
// flip vertical
scaleY *= -1;
// flip horizontal
scaleX *= -1;
[Reply]

Thank you very much, you’ve saved lmy life.
It works great, even for UILoader. (UILoader doesn’t work with the scaleX = -1 trick).
[Reply]