日期:2014-03-14  浏览次数:20796 次

最终效果预览:
 
  源码及其解析:

//直接用AS画的菜单,功用很少,色块会随着鼠标的挪动而挪动.
//以下是主程序.
var menuText = new Array("我收藏的图片", "我收藏的音乐", "我的团体作品",
 "我要看日记本", "如今写信给我", "进我的留言簿");
//菜单的标签.
var menuURL = new Array("http://#", "http://#", "http://#", "http://#",
 "qxiao_xi@tom.com", "http://ningning.dns0755.net");
//菜单标签指向的网址.
var theItem;
//建立MC的时候就用上这个变量.
var i;
//循环变量.
var step;
//色块挪动的步数.
var running;
//判断能否挪动的变量.
//建立新的函数.援用时可直接用this.DrawRect(x,y,w,h);
//x,y-->坐标值,w,h-->宽和高.
MovieClip.prototype.DrawRect = function(x, y, w, h) {
 this.moveTo(x, y);
 this.lineTo(x+w, y);
 this.lineTo(x+w, y+h);
 this.lineTo(x, y+h)
 this.lineTo(x, y);
};
//建立菜单项目的的函数.
//mc-->电影剪辑 x,y-->坐标 w,h-->宽,高. text-->字符串.
function CreateItem(mc, x, y, w, h, text) {
 mc.createTextField("text", 2, x+10, y, 85, 20);
 //建立空的动态文字段
 mc.text.text = text;
 //为新建的动态文字段赋值,颜色,
 mc.text.textColor = 0x000000
 //文字大小有无边框,可否选择.
 mc.text.size = 14;
 mc.text.border = false;
 mc.text.selectable = false;
}
//开始建立菜单的函数.
function CreateMenu(mc) {
 //建立一的电影剪辑,并在上面化一个色块.名字叫bg-->BackGround.
 mc.createEmptyMovieClip("bg", 1); 
 //建立一个空MC
 mc.bg.beginFill(0x33ccff, 100);
 //开始填充
 mc.bg.DrawRect(0, 0, 90, 20);
 //调用函数
 mc.bg.endFill();
 //结束填充
 mc.bg._alpha = 50;
 //通明度
 mc.bg._visible = false;
 //可见度
 //结束绘画.
 //下面开始循环.
 for (i=0; i
  mc.createEmptyMovieClip("item"+i, 2+i);
  theItem = mc["item"+i];
  theItem.index = i;
  CreateItem(theItem, i*90, 0, 90, 20, menuText[i]);
  //桢开始时的动作.
  theItem.onEnterFrame = function() {
   //if语句的默认判断条件是"真"
   //当running==true时.
   if (running) {
    if (mc.bg._x<=step*90) {
     mc.bg._x += 5;
    } else if (mc.bg._x>=step*90+10) {
     mc.bg._x -= 5;
    }
   }
  };
  //经过时的动作.
  theItem.onRollOver = function() {
   mc.bg._visible = true;
   running = true;
   step = this.index;
  };
  //离开时的动作.
  theItem.onRollOut = function() {
   mc.bg._visible = false;
   running = false;
  };
  //单击时的动作.
  theItem.onPress = function() {
   getURL(menuURL[this.index]);
  };
 }
 //循环结束.
}
createEmptyMovieClip("menu", 10);
//建立"menu"电影剪辑.
menu._y = 0;
//坐标值.
menu._x = 0;
CreateMenu(menu);
//建立菜单.
//把这个程序放在场景的第一桢,然后运转.
//我花了一个早上写的东西.还凑和.