首先需要把菜单全部导入,也可以用程序导入到mc。我这里只是写教程,所以只是随便画了个矩形有个效果而已。
不过需要注意的是,必须将单个菜单的坐标对齐到0,0;观看效果:[/url]
[url=http://www.webjx.com/download.php?url=http://www.webjx.com/upfiles/20050923/20050923073940_1.fla]点击这里下载源文件
// Flash AS代码如下;
Stage.align = "TL";
//对其场景为左上角;
Stage.scaleMode = "noScale";
//控制动画不自动缩放;
function BoxCopy(MacMenuName, step, MenuXW, Max, scaleX, MenuX, MenuY) {
createEmptyMovieClip(MacMenuName, 1);
//根据函数参数创建对应的MovieClip;
for (var i = 0; i<Max; i++) {
MacMenuBoxNum = eval(MacMenuName).attachMovie(MacMenuName, "MacMenuBoxName"+i, i);
//根据函数参数给出的菜单个数逐个装载进入刚才创建的MovieClip中;
MacMenuBoxNum.Num.text = i+1;
//此句是用来测试函数的显示结果的;
MacMenuBoxNum.onRelease = function() {
trace(this);
};
//此项定义菜单在点击过后执行的程序;
MacMenuBoxNum.onEnterFrame = scaleBox;
//此句控制调用菜单所放的函数;
}
var MenuBoxHeight = eval(MacMenuName)._height;
onEnterFrame = function () {
MenuX = MenuX == null || MenuX == "" || MenuX == undefined ? 0 : MenuX;
MenuY = MenuY == null || MenuY == "" || MenuY == undefined ? 0 : MenuY;
for (var i = 0; i<Max; i++) {
var MacMenuBoxNum = eval(MacMenuName)["MacMenuBoxName"+i];
// 引用对象;
MacMenuBoxNum._x = eval(MacMenuName)["MacMenuBoxName"+(i-1)]._x+eval(MacMenuName)["MacMenuBoxName"+(i-1)]._width+MenuXW;
// 初始化菜单的排列方式;
MacMenuBoxNum._y = eval(MacMenuName)._y-MacMenuBoxNum._height;
eval(MacMenuName)._x = (Stage.width-eval(MacMenuName)._width)/2+MenuX;
eval(MacMenuName)._y = MenuBoxHeight+MenuY;
// 控制菜单的坐标;
}
};
function scaleBox() {
MouseX = Math.abs(this._x+this._width/2+eval(MacMenuName)._x-_root._xmouse);
MouseY = Math.abs(this._y+eval(MacMenuName)._y-_root._ymouse);
//得到鼠标与菜单的距离;
if (MouseX<=scaleX && MouseY<=MenuBoxHeight*(scaleX+100)/100) {
//得到菜单响应鼠标的有效范围;
this._xscale += (100+(scaleX-MouseX)-this._xscale)/step;
this._yscale += (100+(scaleX-MouseX)-this._yscale)/step;
//缩放菜单的大小;
} else {
this._xscale += (100-this._xscale)/step;
this._yscale += (100-this._yscale)/step;
//还原菜单所放;
}
}
}
BoxCopy("BoxName", 5, 10, 15, 120, 0, 50);
//BoxCopy(attachMovie连接的MovieClip名称,缩放所需要的帧数,各菜单项之间的间距,菜单的总数,缩放的比例,菜单的X坐标,菜单的Y坐标);