效果如下:
http://myarticle.enet.com.cn/images/200503/1112250023206.swf
拖动块上代码:
on (press) {
ymin=_root.tp_mc.tp_mc1._width-_root.tp_mc.drag._width;
xmin=_root.tp_mc.tp_mc1._height-_root.tp_mc.drag._height;
startDrag("_root.tp_mc.drag",false,0,0,ymin,xmin)//拖动按钮,拖动范围设置。
trace(ymin);
trace(xmin);
}
on (release) {
stopDrag();
}//停止拖动
桢上代码:
this.drag._x=0;
this.drag._y=0;//定义拖动块的初始位置;
this.drag1._x=-150;
this.drag1._y=30;//定义遮罩块的初始位置;
this.tp_mc2._x=-150;
this.tp_mc2._y=30;//定义被遮图片的初始位置;
this.drag1._xscale=170;
this.drag1._yscale=170;//遮罩块放大
this.tp_mc2._xscale=170;
this.tp_mc2._yscale=170;//将被遮罩图片放大;
speed=0.5;
xtpmc=_root.tp_mc.tp_mc2._x;
ytpmc=_root.tp_mc.tp_mc2._y;//被遮图片初始位置;
bs=this.tp_mc2._width/this.tp_mc1._width;//大小图片之间倍数;
_root.tp_mc.tp_mc2.setMask(_root.tp_mc.drag1);//遮罩tp_mc2
trace("tp:"+bs);
_root.onEnterFrame=function(){
_root.tp_mc.tp_mc2._x+=((xtpmc+_root.tp_mc.drag._x*-bs)-_root.tp_mc.tp_mc2._x)*speed;
_root.tp_mc.tp_mc2._y+=((ytpmc+_root.tp_mc.drag._y*-bs)-_root.tp_mc.tp_mc2._y)*speed;//缓移;
trace(_root.tp_mc.drag._x*bs)
}