Flash MX 2004自带的Window组件,功能并不丰富。现在,我为它加上了用鼠标调整窗口的大小的功能!!
先看看动画效果:
http://www.flash8.net/bbs/UploadFile/2005-7/200571514459516.swf
函数:
//随鼠标缩放大小函数
//finger:指针
//wLeast:最小宽度
//hLeast:最小高度度
MovieClip.prototype.MouseSetSize = function(finger:String, wLeast:Number, hLeast:Number) {
if (wLeast == undefined) {
wLeast = 50;
}
if (hLeast == undefined) {
hLeast = 30;
}
var depth = this.getNextHighestDepth();//指针深度
var mc = this;
var drag:Boolean = false;//是否可以缩放
var nm:Number;//当前指针序号
var px:Number;//缩放开始时的鼠标x位置
var py:Number;//缩放开始时的鼠标y位置
onMouseMove = function() {
var xm = mc._xmouse;//相对鼠标x位置
var ym = mc._ymouse;//相对鼠标y位置
var w = mc.__width;//组件宽
var h = mc.__height;//组件高
//缩放组件
if (drag) {
if (nm == 1) {
if (px>=4) {
if (xm<wLeast) {
xm = wLeast;
}
mc.setSize(Math.floor(xm), h);
} else {
mc.setSize(w-xm, h);
if (w-xm>=wLeast) {
mc._x = _xmouse;
} else {
mc.setSize(wLeast, h);
}
}
} else if (nm == 2) {
if (py>=4) {
if (ym<hLeast) {
ym = hLeast;
}
mc.setSize(w, Math.floor(ym));
} else {
mc.setSize(w, h-ym);
if (h-ym>=hLeast) {
mc._y = _ymouse;
} else {
mc.setSize(w, hLeast);
}
}
} else if (nm == 3) {
if (py>=4) {
if (ym<hLeast) {
ym = hLeast;
}
mc.setSize(w-xm, Math.floor(ym));
if (w-xm>=wLeast) {
mc._x = _xmouse;
} else {
mc.setSize(wLeast, Math.floor(ym));
}
} else {
if (xm<wLeast) {
xm = wLeast;
}
mc.setSize(Math.floor(xm), h-ym);
if (h-ym>=hLeast) {
mc._y = _ymouse;
} else {
mc.setSize(w, hLeast);
}
}
} else if (nm == 4) {
if (py>=4) {
if (xm<wLeast) {
xm = wLeast;
}
if (ym<hLeast) {
ym = hLeast;
}
mc.setSize(Math.floor(xm), Math.floor(ym));
} else {
mc.setSize(w-xm, h-ym);
if (w-xm>=wLeast) {
mc._x = _xmouse;
} else {
mc.setSize(wLeast, h);
}
if (h-ym>=hLeast) {
mc._y = _ymouse;
} else {
mc.setSize(w, hLeast);
}
}
}
}
//判断是否在范围内
if ((xm>=0 && xm<=w && ym>=0 && ym<=h) && !(xm>=3 && xm<=w-3 && ym>=3 && ym<=h-3)) {
if (mc.mouse == undefined) {
Mouse.hide();
mc.attachMovie(finger, "mouse", depth, {_x:xm, _y:ym});
startDrag(mc.mouse, true);
nm = 1;
}
if (ym>=15 && ym<=h-15) {
if (nm != 1) {
mc.mouse.gotoAndStop(1);
nm = 1;
}
} else if (xm>=15 && xm<=w-15) {
if (nm != 2) {
mc.mouse.gotoAndStop(2);
nm = 2;
}
} else if ((ym<=3 && xm>=w-15) || (ym>=h-3 && xm<=15)) {
if (nm != 3) {
mc.mouse.gotoAndStop(3);
nm = 3;
}
} else if ((ym<=3 && xm<=15) || (ym>=h-3 && xm>=w-15)) {
if (nm != 4) {
mc.mouse.gotoAndStop(4);
nm = 4;
}
}
onMouseDown = function () {
if (mc.mouse != undefined) {
drag = true;
px = xm;
py = ym;
}
};
updateAfterEvent();
} else {
if (mc.mouse != undefined) {
mc.mouse.removeMovieClip();
Mouse.show();
}
}
onMouseUp = function () {
drag = false;
};
};
};
使用窗口.MouseSetSize(finger, wLeast, hLeast) 即可为它加上此功能!
而且,它可以为任何矩形mc加上此功能,只要将__width改为_width, __height改为 _height,把setSize方法改为_width=......,_height=......就可以了。
由于此方法需要使用onMouseMove侦听器,并要判断许多数据,所以不宜为过多窗口同时添加此功能,否则会执行比较慢!