Hi everyone,
i'm having a problem with the transform property of a movieclip. I'm trying to
transform a triangle to another triangle using the transform.matrix property.
The script is as follows:
import flash.geom.Matrix;
import flash.geom.Transform;
obj = createEmptyMovieClip("triangle1", 2);
obj.beginFill(0x00FF00);
obj.moveTo(0, 0);
obj.lineStyle(1,0x0000FF,100,false,'none','none');
obj.lineTo(1, 0);
obj.lineStyle(1,0x00FF00,100,false,'none','none');
obj.lineTo(0, 1);
obj.lineStyle(1,0xFF0000,100,false,'none','none');
obj.endFill;
obj.onPress = function() {
var xn1 = 0;
var yn1 = 0;
var xn2 = 200;
var yn2 = 200;
var xn3 = 0;
var yn3 = 300;
var tmpMat:Matrix = new Matrix(xn2-xn1, xn3-xn1, yn2-yn1, yn3-yn1, xn1, yn1);
this.transform.matrix = tmpMat;
trace(this._xmouse+"---"+this._ymouse)
trace(_root._xmouse+"---"+_root._ymouse)
}
What's it all about? I draw a triangle with points (0,0) to (1,0) to (0,1). I
want to "map" (transform) it to the triangle (0,0)(200,200)(0,300). It is a
well known result that all triangle are affine i.e. there exist a unique affine
transform that send a triangle to another. In this case, the affine transform
is the transfrom.matrix of the movie clip. So, you have 6 variables (the
coordinates of the mapped triangle) and 6 unknown (the elements of the
transform matrix A,B,C,D,Tx,Ty). If you solve the system you get :
A=xn2-xn1
B=xn3-xn1
C=yn2-yn1
D=yn3-yn1
Tx=xn1
Ty=yn1
The problem is that the transform doesn't work correctly. If you run the
script, zoom in at the upper left corner and press on the original triangle,
the new transformed triangle is not what it's supossed to be. I'm running out
of ideas and i think that the "transform.matrix" does not work correctly (maybe
a bug?)...or am i doing something wrong here?