鼠标拖动画一个框,然后滚轮放大框内的图片范围,动态设置图片注册点,图片能比较准确地以选定范围的中心为基准进行放大。
for (var d:Number = 1; d>=0; d--) {//从库中调出两个装有图片的MC,一个用于正常显示,一个用于被放大
attachMovie("img_mc", "img_mc"+d, 100+d, {_x:275, _y:200});
}
var xd:Number = 0;//设置两个参数,来记住鼠标选定范围的中心点
var yd:Number = 0;
function dingwei_func() {
img_mc1.pic_mc._x += img_mc1._x-xd;//改变装有图片的MC的位置,它相对来说就是图片在其父级MC中的注册点了
img_mc1.pic_mc._y += img_mc1._y-yd;
img_mc1._x = xd;//改变被放大MC的坐标,与子级影片pic_mc在上面的坐标变化形成互补,让眼睛感觉图片位置没动
img_mc1._y = yd;
}
//以下是画框动作
var scaleB:Boolean = false;
function draw_func() {
var drawB:Boolean = false;
var xpos:Number = 0;
var ypos:Number = 0;
onMouseDown = function () {
xpos = _xmouse;
ypos = _ymouse;
drawB = true;
//Mouse.removeListener(Mouselistener);
img_mc1._xscale = img_mc1._yscale=100;
};
onMouseMove = function () {
if (drawB) {
this.createEmptyMovieClip("draw_mc", 200);
with (this.draw_mc) {
lineStyle(2, 0xff00ff);
beginFill(0x111111, 0);
moveTo(xpos, ypos);
lineTo(_xmouse, ypos);
lineTo(_xmouse, _ymouse);
lineTo(xpos, _ymouse);
lineTo(xpos, ypos);
endFill();
xd = xpos+(_xmouse-xpos)/2;
yd = ypos+(_ymouse-ypos)/2;
scaleB = true;
}
updateAfterEvent();
}
};
onMouseUp = function () {
this.img_mc1.setMask(draw_mc);
this.draw_mc.duplicateMovieClip(draw_mc2, 222);//由于上面画出来的MC被用作了遮罩,所以这里要复制一个来显示选定范围的边框
dingwei_func();
drawB = false;
};
}
draw_func();
var Mouselistener:Object = new Object();
Mouselistener.onMouseWheel = function(delta) {//这里是滚轮控制大小
if (scaleB == true) {
img_mc1._xscale += delta;
img_mc1._yscale += delta;
}
if (img_mc1._xscale<100 || img_mc1._yscale<100) {//限制只能放大,不能缩小
img_mc1._yscale = img_mc1._xscale=100;
}
};
Mouse.addListener(Mouselistener);
附件: 鼠标选定放大.fla
附件: 鼠标选定放大.swf