im very nex to action script but i've got a problem with an movieclip.
i've got 4 coodinates an need to fit a fit movie clip to them, so each corner of the movieclips is on one coordinate.
The only thing i could find it tranforming it with a matrix and angles (see example), but these cant be the best solution for my problem to calculate all the angles etc.
var degX:Number = 0;
var degY:Number = 0.3;
//Get the transform matrix for the object to skew
var m:Matrix = bild.transform.matrix;
m.b = Math.tan(degY *(Math.PI/180));
m.c = Math.tan(degX *(Math.PI/180));
//Apply the matrix to the transform object
var t:Transform = new Transform(bild);
t.matrix = m;
//Apply the skew
bild.transform = t;
i hope you understand my problem and know a solution for it.
i've tried distord image as it seems to do exaclty what it need but i cant get it so show my image. the coordinates work, if i un comment the commented part i see white retangles exaclty where they should be, but they don't get deleted on update, i hope you cann help my. here is my code:
var PointUR:Point = new Point();
PointUR.x = values1[0];
PointUR.y = values1[1];
var PointUL:Point = new Point();
PointUL.x = values2[0];
PointUL.y = values2[1];
var PointBR:Point = new Point();
PointBR.x = values3[0];
PointBR.y = values3[1];
var PointBL:Point = new Point();
PointBL.x = values4[0];
PointBL.y = values4[1];
[Embed(source='MyImage.jpg')]
var MyImage:Class;
var shape:Shape = new Shape();
var bitmap:Bitmap = new MyImage();
var showGrid:Boolean = true;
var myColorTransform = new ColorTransform();
/*myColorTransform.color = 0xFFFFFF;
shape.transform.colorTransform = myColorTransform;
shape.graphics.beginFill(0x000000,1);
addChild(shape);*/
var distortion:DistortImage = new DistortImage(267, 400, 3, 3);
if (showGrid){
shape.graphics.lineStyle(1, 0x00FF00);
}
distortion.setTransform(shape.graphics,
bitmap.bitmapData,
PointUR,
PointUL,
PointBR,
PointBL);
Transforming a movieClip or Sprite into a trapezoid using the matrix is impossible in as3. Check out this link that explains the extent of possibilities
in short:
The way this has been achieved is by breaking up the DisplayObject into smaller triangles, and applying different translation matrix to each. The end result makes the triangles pop out a bit, but if you increase the number of triangles, this effect gets diminished.
here's a link for a blog with demo and source
It is much easier to do this with 3d classes or Mathieu Badimon's five3d, the distortion part anyway, I'm not sure how you would do it to match a set of control points.