Flash制作仿苹果界面的互动图标界面
这个菜单是06年学“类”时写的菜单效果,模仿苹果机中的菜单效果。
大家可以试试,用鼠标划过图标时,该图标会放大,画面以此图标为中心向两边缩放。Flash AS代码入下:
/** *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 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 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 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; } } |