设为首页 加入收藏

TOP

Flash AS制作的仿苹果机的导航菜单
2012-11-03 15:54:19 来源:网络 作者: 【 】 浏览:1251次 评论:0

模仿苹果机中的菜单效果,鼠标经过图标时,以该图标为中心向两边缩放。



/**
 *MacintoshMenu(仿苹果机菜单)
 *Auther:流浪儿
 *Versoin:MacintoshMenu 1.0
**/
class MacintoshMenu {
 //属性
 private var target:MovieClip;
 private var imageContainer:MovieClip;
 private var imageArr:Array;
 private var total:Number;
 private var spanX:Number = 5;
 private var ypos:Number = Stage.height/2+50;
 //构造函数
 public function MacintoshMenu(target:MovieClip, imageArr:Array, scale:Number) {
  this.target = target;
  this.imageArr = imageArr;
  //
  total = imageArr.length;
  imageContainer = target.createEmptyMovieClip("imageContainer", 1);
  attachMc(scale);
  resetPosition();
 }
 //加载图片
 private function attachMc(scale:Number):Void {
  for (var i:Number = 0; i<total; i++) {
   var menu:MovieClip = imageContainer.attachMovie(imageArr[i], "menu"+i, i);
   mouseControlZoomEffect(menu, scale);
   menu.onRollOver = function() {
    //trace(this._name);
   };
  }
 }
 //鼠标控制缩放比例效果
 private function mouseControlZoomEffect(mc:MovieClip, scale:Number):Void {
  var owner:Object = this;//用一个临时变量指向当前类
  mc.onEnterFrame = function() {
   var mouseX:Number = Math.abs(this._x+this._width/2+owner.imageContainer._x-owner.imageContainer._parent._xmouse);
   //trace(mc._name+">>> "+mouseX);trace("");
   if (owner.imageContainer.hitTest(owner.target._xmouse, owner.target._ymouse)) {
    if (mouseX<scale) {
     var num:Number = 100+scale-mouseX;
     owner.zoomEffect(this, num);
    } else {
     owner.zoomEffect(this, 100);
    }
   } else {
    owner.zoomEffect(this, 100);
   }
   updateAfterEvent();
  };
 }
 //缩放效果
 private function zoomEffect(mc:MovieClip, scale:Number):Void {
  var ratio:Number = .4;
  mc._xscale = mc._yscale += (scale-mc._xscale)*ratio;
 }
 //重新设置各菜单的位置
 private function resetPosition():Void {
  var owner:Object = this;
  target.onEnterFrame = function() {
   for (var i:Number = 0; i<owner.total; i++) {
    var menu:MovieClip = owner.imageContainer["menu"+i];
    menu._x = owner.imageContainer["menu"+(i-1)]._x+owner.imageContainer["menu"+(i-1)]._width+owner.spanX;
    menu._y = owner.ypos-menu._height;
    owner.imageContainer._x = (Stage.width-owner.imageContainer._width)/2;
   }
   updateAfterEvent();
  };
 }
 //转义(位置、间距等)
 public function get _ypos():Number {
  return this.ypos;
 }
 public function set _ypos(values:Number):Void {
  this.ypos = values;
 }
 public function get _spanX():Number {
  return this.spanX;
 }
 public function set _spanX(values:Number):Void {
  this.spanX = values;
 }
 public function get _x():Number {
  return this.target._x;
 }
 public function set _x(values:Number):Void {
  this.target._x = values;
 }
 public function get _y():Number {
  return this.target._y;
 }
 public function set _y(values:Number):Void {
  this.target._y = values;
 }
}


/**
 *MacintoshMenu(仿苹果机菜单)
 *Auther:流浪儿
 *Versoin:MacintoshMenu 1.0
**/
class MacintoshMenu {
 //属性
 private var target:MovieClip;
 private var imageContainer:MovieClip;
 private var imageArr:Array;
 private var total:Number;
 private var spanX:Number = 5;
 private var ypos:Number = Stage.height/2+50;
 //构造函数
 public function MacintoshMenu(target:MovieClip, imageArr:Array, scale:Number) {
  this.target = target;
  this.imageArr = imageArr;
  //
  total = imageArr.length;
  imageContainer = target.createEmptyMovieClip("imageContainer", 1);
  attachMc(scale);
  resetPosition();
 }
 //加载图片
 private function attachMc(scale:Number):Void {
  for (var i:Number = 0; i<total; i++) {
   var menu:MovieClip = imageContainer.attachMovie(imageArr[i], "menu"+i, i);
   mouseControlZoomEffect(menu, scale);
   menu.onRollOver = function() {
    //trace(this._name);
   };
  }
 }
 //鼠标控制缩放比例效果
 private function mouseControlZoomEffect(mc:MovieClip, scale:Number):Void {
  var owner:Object = this;//用一个临时变量指向当前类
  mc.onEnterFrame = function() {
   var mouseX:Number = Math.abs(this._x+this._width/2+owner.imageContainer._x-owner.imageContainer._parent._xmouse);
   //trace(mc._name+">>> "+mouseX);trace("");
   if (owner.imageContainer.hitTest(owner.target._xmouse, owner.target._ymouse)) {
    if (mouseX<scale) {
     var num:Number = 100+scale-mouseX;
     owner.zoomEffect(this, num);
    } else {
     owner.zoomEffect(this, 100);
    }
   } else {
    owner.zoomEffect(this, 100);
   }
   updateAfterEvent();
  };
 }
 //缩放效果
 private function zoomEffect(mc:MovieClip, scale:Number):Void {
  var ratio:Number = .4;
  mc._xscale = mc._yscale += (scale-mc._xscale)*ratio;
 }
 //重新设置各菜单的位置
 private function resetPosition():Void {
  var owner:Object = this;
  target.onEnterFrame = function() {
   for (var i:Number = 0; i<owner.total; i++) {
    var menu:MovieClip = owner.imageContainer["menu"+i];
    menu._x = owner.imageContainer["menu"+(i-1)]._x+owner.imageContainer["menu"+(i-1)]._width+owner.spanX;
    menu._y = owner.ypos-menu._height;
    owner.imageContainer._x = (Stage.width-owner.imageContainer._width)/2;
   }
   updateAfterEvent();
  };
 }
 //转义(位置、间距等)
 public function get _ypos():Number {
  return this.ypos;
 }
 public function set _ypos(values:Number):Void {
  this.ypos = values;
 }
 public function get _spanX():Number {
  return this.spanX;
 }
 public function set _spanX(values:Number):Void {
  this.spanX = values;
 }
 public function get _x():Number {
  return this.target._x;
 }
 public function set _x(values:Number):Void {
  this.target._x = values;
 }
 public function get _y():Number {
  return this.target._y;
 }
 public function set _y(values:Number):Void {
  this.target._y = values;
 }
}

 


/**
 *MacintoshMenu(仿苹果机菜单)
 *Auther:流浪儿
 *Versoin:MacintoshMenu 1.0
**/
class MacintoshMenu {
 //属性
 private var target:MovieClip;
 private var imageContainer:MovieClip;
 private var imageArr:Array;
 private var total:Number;
 private var spanX:Number = 5;
 private var ypos:Number = Stage.height/2+50;
 //构造函数
 public function MacintoshMenu(target:MovieClip, imageArr:Array, scale:Number) {
  this.target = target;
  this.imageArr = imageArr;
  //
  total = imageArr.length;
  imageContainer = target.createEmptyMovieClip("imageContainer", 1);
  attachMc(scale);
  resetPosition();
 }
 //加载图片
 private function attachMc(scale:Number):Void {
  for (var i:Number = 0; i<total; i++) {
   var menu:MovieClip = imageContainer.attachMovie(imageArr[i], "menu"+i, i);
   mouseControlZoomEffect(menu, scale);
   menu.onRollOver = function() {
    //trace(this._name);
   };
  }
 }
 //鼠标控制缩放比例效果
 private function mouseControlZoomEffect(mc:MovieClip, scale:Number):Void {
  var owner:Object = this;//用一个临时变量指向当前类
  mc.onEnterFrame = function() {
   var mouseX:Number = Math.abs(this._x+this._width/2+owner.imageContainer._x-owner.imageContainer._parent._xmouse);
   //trace(mc._name+">>> "+mouseX);trace("");
   if (owner.imageContainer.hitTest(owner.target._xmouse, owner.target._ymouse)) {
    if (mouseX<scale) {
     var num:Number = 100+scale-mouseX;
     owner.zoomEffect(this, num);
    } else {
     owner.zoomEffect(this, 100);
    }
   } else {
    owner.zoomEffect(this, 100);
   }
   updateAfterEvent();
  };
 }
 //缩放效果
 private function zoomEffect(mc:MovieClip, scale:Number):Void {
  var ratio:Number = .4;
  mc._xscale = mc._yscale += (scale-mc._xscale)*ratio;
 }
 //重新设置各菜单的位置
 private function resetPosition():Void {
  var owner:Object = this;
  target.onEnterFrame = function() {
   for (var i:Number = 0; i<owner.total; i++) {
    var menu:MovieClip = owner.imageContainer["menu"+i];
    menu._x = owner.imageContainer["menu"+(i-1)]._x+owner.imageContainer["menu"+(i-1)]._width+owner.spanX;
    menu._y = owner.ypos-menu._height;
    owner.imageContainer._x = (Stage.width-owner.imageContainer._width)/2;
   }
   updateAfterEvent();
  };
 }
 //转义(位置、间距等)
 public function get _ypos():Number {
  return this.ypos;
 }
 public function set _ypos(values:Number):Void {
  this.ypos = values;
 }
 public function get _spanX():Number {
  return this.spanX;
 }
 public function set _spanX(values:Number):Void {
  this.spanX = values;
 }
 public function get _x():Number {
  return this.target._x;
 }
 public function set _x(values:Number):Void {
  this.target._x = values;
 }
 public function get _y():Number {
  return this.target._y;
 }
 public function set _y(values:Number):Void {
  this.target._y = values;
 }
}

 


/**
 *MacintoshMenu(仿苹果机菜单)
 *Auther:流浪儿
 *Versoin:MacintoshMenu 1.0
**/
class MacintoshMenu {
 //属性
 private var target:MovieClip;
 private var imageContainer:MovieClip;
 private var imageArr:Array;
 private var total:Number;
 private var spanX:Number = 5;
 private var ypos:Number = Stage.height/2+50;
 //构造函数
 public function MacintoshMenu(target:MovieClip, imageArr:Array, scale:Number) {
  this.target = target;
  this.imageArr = imageArr;
  //
  total = imageArr.length;
  imageContainer = target.createEmptyMovieClip("imageContainer", 1);
  attachMc(scale);
  resetPosition();
 }
 //加载图片
 private function attachMc(scale:Number):Void {
  for (var i:Number = 0; i<total; i++) {
   var menu:MovieClip = imageContainer.attachMovie(imageArr[i], "menu"+i, i);
   mouseControlZoomEffect(menu, scale);
   menu.onRollOver = function() {
    //trace(this._name);
   };
  }
 }
 //鼠标控制缩放比例效果
 private function mouseControlZoomEffect(mc:MovieClip, scale:Number):Void {
  var owner:Object = this;//用一个临时变量指向当前类
  mc.onEnterFrame = function() {
   var mouseX:Number = Math.abs(this._x+this._width/2+owner.imageContainer._x-owner.imageContainer._parent._xmouse);
   //trace(mc._name+">>> "+mouseX);trace("");
   if (owner.imageContainer.hitTest(owner.target._xmouse, owner.target._ymouse)) {
    if (mouseX<scale) {
     var num:Number = 100+scale-mouseX;
     owner.zoomEffect(this, num);
    } else {
     owner.zoomEffect(this, 100);
    }
   } else {
    owner.zoomEffect(this, 100);
   }
   updateAfterEvent();
  };
 }
 //缩放效果
 private function zoomEffect(mc:MovieClip, scale:Number):Void {
  var ratio:Number = .4;
  mc._xscale = mc._yscale += (scale-mc._xscale)*ratio;
 }
 //重新设置各菜单的位置
 private function resetPosition():Void {
  var owner:Object = this;
  target.onEnterFrame = function() {
   for (var i:Number = 0; i<owner.total; i++) {
    var menu:MovieClip = owner.imageContainer["menu"+i];
    menu._x = owner.imageContainer["menu"+(i-1)]._x+owner.imageContainer["menu"+(i-1)]._width+owner.spanX;
    menu._y = owner.ypos-menu._height;
    owner.imageContainer._x = (Stage.width-owner.imageContainer._width)/2;
   }
   updateAfterEvent();
  };
 }
 //转义(位置、间距等)
 public function get _ypos():Number {
  return this.ypos;
 }
 public function set _ypos(values:Number):Void {
  this.ypos = values;
 }
 public function get _spanX():Number {
  return this.spanX;
 }
 public function set _spanX(values:Number):Void {
  this.spanX = values;
 }
 public function get _x():Number {
  return this.target._x;
 }
 public function set _x(values:Number):Void {
  this.target._x = values;
 }
 public function get _y():Number {
  return this.target._y;
 }
 public function set _y(values:Number):Void {
  this.target._y = values;
 }
}


/**
 *MacintoshMenu(仿苹果机菜单)
 *Auther:流浪儿
 *Versoin:MacintoshMenu 1.0
**/
class MacintoshMenu {
 //属性
 private var target:MovieClip;
 private var imageContainer:MovieClip;
 private var imageArr:Array;
 private var total:Number;
 private var spanX:Number = 5;
 private var ypos:Number = Stage.height/2+50;
 //构造函数
 public function MacintoshMenu(target:MovieClip, imageArr:Array, scale:Number) {
  this.target = target;
  this.imageArr = imageArr;
  //
  total = imageArr.length;
  imageContainer = target.createEmptyMovieClip("imageContainer", 1);
  attachMc(scale);
  resetPosition();
 }
 //加载图片
 private function attachMc(scale:Number):Void {
  for (var i:Number = 0; i<total; i++) {
   var menu:MovieClip = imageContainer.attachMovie(imageArr[i], "menu"+i, i);
   mouseControlZoomEffect(menu, scale);
   menu.onRollOver = function() {
    //trace(this._name);
   };
  }
 }
 //鼠标控制缩放比例效果
 private function mouseControlZoomEffect(mc:MovieClip, scale:Number):Void {
  var owner:Object = this;//用一个临时变量指向当前类
  mc.onEnterFrame = function() {
   var mouseX:Number = Math.abs(this._x+this._width/2+owner.imageContainer._x-owner.imageContainer._parent._xmouse);
   //trace(mc._name+">>> "+mouseX);trace("");
   if (owner.imageContainer.hitTest(owner.target._xmouse, owner.target._ymouse)) {
    if (mouseX<scale) {
     var num:Number = 100+scale-mouseX;
     owner.zoomEffect(this, num);
    } else {
     owner.zoomEffect(this, 100);
    }
   } else {
    owner.zoomEffect(this, 100);
   }
   updateAfterEvent();
  };
 }
 //缩放效果
 private function zoomEffect(mc:MovieClip, scale:Number):Void {
  var ratio:Number = .4;
  mc._xscale = mc._yscale += (scale-mc._xscale)*ratio;
 }
 //重新设置各菜单的位置
 private function resetPosition():Void {
  var owner:Object = this;
  target.onEnterFrame = function() {
   for (var i:Number = 0; i<owner.total; i++) {
    var menu:MovieClip = owner.imageContainer["menu"+i];
    menu._x = owner.imageContainer["menu"+(i-1)]._x+owner.imageContainer["menu"+(i-1)]._width+owner.spanX;
    menu._y = owner.ypos-menu._height;
    owner.imageContainer._x = (Stage.width-owner.imageContainer._width)/2;
   }
   updateAfterEvent();
  };
 }
 //转义(位置、间距等)
 public function get _ypos():Number {
  return this.ypos;
 }
 public function set _ypos(values:Number):Void {
  this.ypos = values;
 }
 public function get _spanX():Number {
  return this.spanX;
 }
 public function set _spanX(values:Number):Void {
  this.spanX = values;
 }
 public function get _x():Number {
  return this.target._x;
 }
 public function set _x(values:Number):Void {
  this.target._x = values;
 }
 public function get _y():Number {
  return this.target._y;
 }
 public function set _y(values:Number):Void {
  this.target._y = values;
 }
}

 

 
 
Tags:Flash AS 苹果 导航 菜单 责任编辑:风花雪月
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇轻松实现多个MC自动连播 下一篇Flash AS实现的波纹视觉特效

评论

帐  号:
密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章