演示效果如下:
点击这里下载源文件
//此为测试程序,因此只显示了效果,以下为AS脚本----------------------------------
stageL = 0;
stageT = 30;
stageR = Stage.width;
stageB = Stage.height;
//以上为初始化选区范围;
var my_mc = new Array();
//创建用于存储mc的数组;
onload();
reload_btn.onRelease = function() {
onload();
};
function onload() {
for (i=1; i<10; i++) {
test0.duplicateMovieClip("test"+i, i);
}
for (i=0; i<10; i++) {
my_mc.push(eval("test"+i));
tests = eval("test"+i);
tests._alpha = 100;
tests._x = random(200)+100;
tests._y = random(200)+100;
}
}
//初始化动画元素;
var mouseObj = new Object();
Mouse.addListener(mouseObj);
//监听鼠标事件;
mouseObj.onMouseDown = function() {
if (_xmouse>stageL && _xmouse<stageR && _ymouse>stageT && _ymouse<stageB) {
box_x = _xmouse;
box_y = _ymouse;
createEmptyMovieClip("box_mc", 50);
with (box_mc) {
lineStyle(1, 0xff0000, 80);
beginFill(0xff0000, 10);
moveTo(0, 0);
lineTo(0, 1000);
lineTo(1000, 1000);
lineTo(1000, 0);
lineTo(0, 0);
endFill();
_width = 1;
_height = 1;
}
box_mc.onEnterFrame = function() {
this._width = Math.abs(_xmouse-box_x);
this._height = Math.abs(_ymouse-box_y);
this._x = _xmouse<box_x ? _xmouse : box_x;
this._y = _ymouse<box_y ? _ymouse : box_y;
};
}
};
//以上为在选区范围内创建选框;
mouseObj.onMouseUp = function() {
//本函数为处理选框范围内的数据;
if (box_mc != undefined) {
//如果选框以被结构边执行control函数;
control();
box_mc.removeMovieClip();
}
};
function control() {
for (i=0; i<my_mc.length; i++) {
if (box_mc.hitTest(my_mc[i])) {
//以下程序为操作在选框范围内或者和选框接触了的mc所要执行的事件;
hits = my_mc[i];
hits._alpha = 40;
//为了可视化效果,我将被选种的所有mc的通明度改变了。
}
}
}