import flash.geom.Matrix;
import flash.display.BitmapData;
var map:BitmapData = new BitmapData(mc.width,mc.height);
map.draw(mc);
var _testPic:BitmapData=new testPic();
var _w:Number=map.width;
var _h:Number=map.height;
var m1:Matrix =new Matrix();
var m2:Matrix =new Matrix();
var ap:Array = [];
var at:Array = [];
var tempmc:MovieClip;
for (var i:int=1; i<=3; i++)
{
var mk:MovieClip =getChildByName("mc"+i) as MovieClip;
var xPos:Number = 550 * Math.random();
var yPos:Number = 400 * Math.random();
ap[i - 1] = new Point(mk.x,mk.y);//new Point(xPos,yPos);
at[i - 1] = new Point(mk.x,mk.y);///new Point(xPos,yPos);
//mk.x = xPos;mk.y = yPos;
mk.addEventListener(MouseEvent.MOUSE_DOWN ,down);
}
m1.tx = at[0].x;
m1.ty = at[0].y;
m1.a=(at[1].x-at[0].x)/_w;
m1.b=(at[1].y-at[0].y)/_w;
m1.c=(at[2].x-at[0].x)/_h;
m1.d=(at[2].y-at[0].y)/_h;
m1.invert();
trace(_w,_h);
//ff(ap[0],ap[1],ap[2],m1);
tempmc = mc1;
d(null);
function down(e:MouseEvent )
{
tempmc = e.currentTarget as MovieClip;
tempmc.startDrag();
stage.addEventListener(MouseEvent.MOUSE_MOVE ,d);
stage.addEventListener(MouseEvent.MOUSE_UP ,up);
}
function d(e:MouseEvent )
{
var n:Number = Number(tempmc.name.substr(2,1)) - 1;
//修改ap数组中移动点对应的值
ap[n].x = tempmc.x;
ap[n].y = tempmc.y;
//m1是初始矩阵
var m3:Matrix=m1.clone();
//m2是变化矩阵
m2.tx = ap[0].x;
m2.ty = ap[0].y;
m2.a=(ap[1].x-ap[0].x)/_w;
m2.b=(ap[1].y-ap[0].y)/_w;
m2.c=(ap[2].x-ap[0].x)/_h;
m2.d=(ap[2].y-ap[0].y)/_h;
m3.concat(m2);
//trace(m1)
ff(ap[0],ap[1],ap[2],m3,m2);
}
function up(e:MouseEvent )
{
tempmc.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_MOVE ,d);
stage.removeEventListener(MouseEvent.MOUSE_UP ,up);
}
function ff(p1:Point,p2:Point,p3:Point,m:Matrix,_m:Matrix)
{
mc.transform.matrix=m;
graphics.clear();
//graphics.beginBitmapFill(_testPic,_m);
graphics.beginFill(0x99ccff,.4);
graphics.moveTo(p1.x,p1.y);
graphics.lineTo(p3.x,p3.y);
graphics.lineTo(p2.x,p2.y);
graphics.lineTo(p1.x,p1.y);
}
import flash.display.BitmapData;
var map:BitmapData = new BitmapData(mc.width,mc.height);
map.draw(mc);
var _testPic:BitmapData=new testPic();
var _w:Number=map.width;
var _h:Number=map.height;
var m1:Matrix =new Matrix();
var m2:Matrix =new Matrix();
var ap:Array = [];
var at:Array = [];
var tempmc:MovieClip;
for (var i:int=1; i<=3; i++)
{
var mk:MovieClip =getChildByName("mc"+i) as MovieClip;
var xPos:Number = 550 * Math.random();
var yPos:Number = 400 * Math.random();
ap[i - 1] = new Point(mk.x,mk.y);//new Point(xPos,yPos);
at[i - 1] = new Point(mk.x,mk.y);///new Point(xPos,yPos);
//mk.x = xPos;mk.y = yPos;
mk.addEventListener(MouseEvent.MOUSE_DOWN ,down);
}
m1.tx = at[0].x;
m1.ty = at[0].y;
m1.a=(at[1].x-at[0].x)/_w;
m1.b=(at[1].y-at[0].y)/_w;
m1.c=(at[2].x-at[0].x)/_h;
m1.d=(at[2].y-at[0].y)/_h;
m1.invert();
trace(_w,_h);
//ff(ap[0],ap[1],ap[2],m1);
tempmc = mc1;
d(null);
function down(e:MouseEvent )
{
tempmc = e.currentTarget as MovieClip;
tempmc.startDrag();
stage.addEventListener(MouseEvent.MOUSE_MOVE ,d);
stage.addEventListener(MouseEvent.MOUSE_UP ,up);
}
function d(e:MouseEvent )
{
var n:Number = Number(tempmc.name.substr(2,1)) - 1;
//修改ap数组中移动点对应的值
ap[n].x = tempmc.x;
ap[n].y = tempmc.y;
//m1是初始矩阵
var m3:Matrix=m1.clone();
//m2是变化矩阵
m2.tx = ap[0].x;
m2.ty = ap[0].y;
m2.a=(ap[1].x-ap[0].x)/_w;
m2.b=(ap[1].y-ap[0].y)/_w;
m2.c=(ap[2].x-ap[0].x)/_h;
m2.d=(ap[2].y-ap[0].y)/_h;
m3.concat(m2);
//trace(m1)
ff(ap[0],ap[1],ap[2],m3,m2);
}
function up(e:MouseEvent )
{
tempmc.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_MOVE ,d);
stage.removeEventListener(MouseEvent.MOUSE_UP ,up);
}
function ff(p1:Point,p2:Point,p3:Point,m:Matrix,_m:Matrix)
{
mc.transform.matrix=m;
graphics.clear();
//graphics.beginBitmapFill(_testPic,_m);
graphics.beginFill(0x99ccff,.4);
graphics.moveTo(p1.x,p1.y);
graphics.lineTo(p3.x,p3.y);
graphics.lineTo(p2.x,p2.y);
graphics.lineTo(p1.x,p1.y);
}