flash实现苹果菜单效果代码
代码如下:
package com.TangWeiChun.MenuClass{
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AppleMenu extends MovieClip {
public var IcoArray:Array=[];
public var scalelimit:Array=[0.2,0.5];
public var time:Timer=new Timer(1000/35);
public var Target_Obj:Object;
public var BM_ori_wid:Number;
public var buffer:Boolean;
//缓冲?
public var f_mc:MovieClip=new MovieClip();
public var ori_all_wid:Number;
public var beishu=3;
//有效距离3倍的单个图标宽度 可调
public function AppleMenu(target_mc:Object,IcoArr) {
Target_Obj=target_mc;
IcoArray=IcoArr;
init();
addIco(target_mc);
}
public function init() {
time.addEventListener(TimerEvent.TIMER,Func);
buffer=false;
f_mc.x=mouseX;
f_mc.y=mouseY;
time.start();
}
public function addIco(target_obj:Object) {
for (var j=0; j<IcoArray.length; j++) {
var BMD=new IcoArray[j](0,0);
var BM:Bitmap=new Bitmap(BMD);
BM_ori_wid=BM.width;
var p:Number=scalelimit[0];
BM.width=BM.width*p;
BM.height=BM.height*p;
BM.smoothing=true;
var mc0:MovieClip=new MovieClip();
BM.x=-BM.width/2;
BM.y=-BM.height/2;
mc0.addChild(BM);
var mc:MovieClip=new MovieClip();
mc.addChild(mc0);
ori_all_wid=mc.width*(IcoArray.length-1);
mc.x=BM.width*j;
target_obj.addChild(mc);
mc.ori_x=mc.x;
mc.ori_y=mc.y;
mc.ori_stage_x=mc.x+mc.parent.x;
mc.ori_stage_y=mc.y+mc.parent.y;
mc.ori_width=mc.width;
mc.ori_height=mc.height;
mc.name="Ico_"+j;
mc.links="http://www.www.com/"+j+".html";
mc.addEventListener(MouseEvent.MOUSE_DOWN,MD_event);
}
}
public function MD_event(e:MouseEvent) {
trace(e.target.parent.links);
}
public function Func(event:TimerEvent) {
event.updateAfterEvent();
if (buffer) {
f_mc.x+=(mouseX-f_mc.x)/7;
f_mc.y+=(mouseY-f_mc.y)/7;
} else {
f_mc.x=mouseX;
f_mc.y=mouseY;
}
var all_wid=0;
for (var j=0; j<IcoArray.length; j++) {
var T_x:Number=Target_Obj.getChildByName("Ico_"+j).ori_stage_x;
var T_y:Number=Target_Obj.getChildByName("Ico_"+j).ori_stage_y;
var wid:Number=Target_Obj.getChildByName("Ico_"+j).ori_width;
all_wid+=Target_Obj.getChildByName("Ico_"+j).width;
if (f_mc.x>=T_x&&f_mc.x-T_x<=wid* beishu) {
Target_Obj.getChildByName("Ico_"+j).width=wid+((wid* beishu)-(f_mc.x-T_x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
Target_Obj.getChildByName("Ico_"+j).height=wid+((wid* beishu)-(f_mc.x-T_x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
} else if (f_mc.x<T_x&&T_x-f_mc.x<wid * beishu) {
Target_Obj.getChildByName("Ico_"+j).width=wid+((wid* beishu)-(T_x-f_mc.x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
Target_Obj.getChildByName("Ico_"+j).height=wid+((wid* beishu)-(T_x-f_mc.x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
} else {
Target_Obj.getChildByName("Ico_"+j).width=wid;
Target_Obj.getChildByName("Ico_"+j).height=wid;
}
}
Target_Obj.getChildByName("Ico_"+0).x=Target_Obj.getChildByName("Ico_"+0).ori_x-((all_wid-Target_Obj.getChildByName("Ico_"+0).width)-ori_all_wid)/2;
for (var jj=1; jj<IcoArray.length; jj++) {
Target_Obj.getChildByName("Ico_"+jj).x=Target_Obj.getChildByName("Ico_"+(jj-1)).x+Target_Obj.getChildByName("Ico_"+(jj-1)).width/2+Target_Obj.getChildByName("Ico_"+(jj)).width/2;
}
}
}
}
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AppleMenu extends MovieClip {
public var IcoArray:Array=[];
public var scalelimit:Array=[0.2,0.5];
public var time:Timer=new Timer(1000/35);
public var Target_Obj:Object;
public var BM_ori_wid:Number;
public var buffer:Boolean;
//缓冲?
public var f_mc:MovieClip=new MovieClip();
public var ori_all_wid:Number;
public var beishu=3;
//有效距离3倍的单个图标宽度 可调
public function AppleMenu(target_mc:Object,IcoArr) {
Target_Obj=target_mc;
IcoArray=IcoArr;
init();
addIco(target_mc);
}
public function init() {
time.addEventListener(TimerEvent.TIMER,Func);
buffer=false;
f_mc.x=mouseX;
f_mc.y=mouseY;
time.start();
}
public function addIco(target_obj:Object) {
for (var j=0; j<IcoArray.length; j++) {
var BMD=new IcoArray[j](0,0);
var BM:Bitmap=new Bitmap(BMD);
BM_ori_wid=BM.width;
var p:Number=scalelimit[0];
BM.width=BM.width*p;
BM.height=BM.height*p;
BM.smoothing=true;
var mc0:MovieClip=new MovieClip();
BM.x=-BM.width/2;
BM.y=-BM.height/2;
mc0.addChild(BM);
var mc:MovieClip=new MovieClip();
mc.addChild(mc0);
ori_all_wid=mc.width*(IcoArray.length-1);
mc.x=BM.width*j;
target_obj.addChild(mc);
mc.ori_x=mc.x;
mc.ori_y=mc.y;
mc.ori_stage_x=mc.x+mc.parent.x;
mc.ori_stage_y=mc.y+mc.parent.y;
mc.ori_width=mc.width;
mc.ori_height=mc.height;
mc.name="Ico_"+j;
mc.links="http://www.www.com/"+j+".html";
mc.addEventListener(MouseEvent.MOUSE_DOWN,MD_event);
}
}
public function MD_event(e:MouseEvent) {
trace(e.target.parent.links);
}
public function Func(event:TimerEvent) {
event.updateAfterEvent();
if (buffer) {
f_mc.x+=(mouseX-f_mc.x)/7;
f_mc.y+=(mouseY-f_mc.y)/7;
} else {
f_mc.x=mouseX;
f_mc.y=mouseY;
}
var all_wid=0;
for (var j=0; j<IcoArray.length; j++) {
var T_x:Number=Target_Obj.getChildByName("Ico_"+j).ori_stage_x;
var T_y:Number=Target_Obj.getChildByName("Ico_"+j).ori_stage_y;
var wid:Number=Target_Obj.getChildByName("Ico_"+j).ori_width;
all_wid+=Target_Obj.getChildByName("Ico_"+j).width;
if (f_mc.x>=T_x&&f_mc.x-T_x<=wid* beishu) {
Target_Obj.getChildByName("Ico_"+j).width=wid+((wid* beishu)-(f_mc.x-T_x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
Target_Obj.getChildByName("Ico_"+j).height=wid+((wid* beishu)-(f_mc.x-T_x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
} else if (f_mc.x<T_x&&T_x-f_mc.x<wid * beishu) {
Target_Obj.getChildByName("Ico_"+j).width=wid+((wid* beishu)-(T_x-f_mc.x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
Target_Obj.getChildByName("Ico_"+j).height=wid+((wid* beishu)-(T_x-f_mc.x))/(wid* beishu)*(scalelimit[1]*BM_ori_wid-wid);
} else {
Target_Obj.getChildByName("Ico_"+j).width=wid;
Target_Obj.getChildByName("Ico_"+j).height=wid;
}
}
Target_Obj.getChildByName("Ico_"+0).x=Target_Obj.getChildByName("Ico_"+0).ori_x-((all_wid-Target_Obj.getChildByName("Ico_"+0).width)-ori_all_wid)/2;
for (var jj=1; jj<IcoArray.length; jj++) {
Target_Obj.getChildByName("Ico_"+jj).x=Target_Obj.getChildByName("Ico_"+(jj-1)).x+Target_Obj.getChildByName("Ico_"+(jj-1)).width/2+Target_Obj.getChildByName("Ico_"+(jj)).width/2;
}
}
}
}
导入类:
import com.TangWeiChun.MenuClass.AppleMenu;
//导入类
var IcoArr:Array=[T贝贝,T欢欢,T2008,T晶晶,T妮妮,T迎迎];
//图标类名数组
var myAppleMenu:AppleMenu=new AppleMenu(Container_mc,IcoArr);
//创建一个实例
myAppleMenu.buffer=true;
//导入类
var IcoArr:Array=[T贝贝,T欢欢,T2008,T晶晶,T妮妮,T迎迎];
//图标类名数组
var myAppleMenu:AppleMenu=new AppleMenu(Container_mc,IcoArr);
//创建一个实例
myAppleMenu.buffer=true;
补充:flash教程,As3.0