当前位置:软件学习 > Flash >>

仿苹果电脑的导航菜单

06年学类时,写的菜单效果。模仿苹果机中的菜单效果,鼠标经过图标时,以该图标为中心向两边缩放。  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;
 }
}

补充:flash教程,Flash游戏
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,