最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
as3.0 导航栏菜单实例
时间:2022-07-02 17:02:50 编辑:袖梨 来源:一聚教程网
代码:
//设置帧速
stage.frameRate=30
//申明一些变量
var namearray:Array=new Array("闪吧","动漫","教材","素材","论坛");
var urlarray:Array=new Array("","/flash",
"/teach","/download.shtml",
"http://space.flash8.net/bbs");
var btn:SimpleButton;
var k:uint;
var url:URLRequest;
var t:Timer=new Timer(30);
var X0:Number;
var Y0:Number;
//创建按钮
for (k=0; k
btn.x=50*k+100;
btn.y=50;
btn.upState=hua(0x006600);
btn.overState=hua(0x009900);
btn.downState=hua(0x006600);
btn.hitTestState=btn.upState;
btn.addEventListener(MouseEvent.MOUSE_MOVE,jg);
btn.addEventListener(MouseEvent.CLICK,dj);
var txt:TextField=new TextField();
txt.autoSize=TextFieldAutoSize.CENTER;
txt.textColor=0xffffff;
txt.text=namearray[k];
txt.x=(btn.width-txt.width)/2+btn.x;
txt.y=(btn.height-txt.height)/2+btn.y;
addChild(btn);
addChild(txt);
txt.mouseEnabled=false;
}
function hua(color:uint):Shape {
var circle:Shape=new Shape();
circle.graphics.beginFill(color);
circle.graphics.drawRect(0,0,50,20);
circle.graphics.endFill();
return circle;
}
//按钮指示
var zs:Sprite=new Sprite();
zs.graphics.beginFill(0x009900);
zs.graphics.moveTo(-5,15);
zs.graphics.lineTo(5,15);
zs.graphics.lineTo(0,10);
zs.graphics.lineTo(-5,15);
zs.graphics.endFill();
zs.x=125;
zs.y=35;
addChild(zs);
//按钮指示的坐标设置
t.addEventListener("timer",js);
function js(e:TimerEvent):void {
var dx:Number=X0-zs.x;
var dy:Number=Y0-zs.y;
var jl:Number=Math.sqrt(dx*dx+dy*dy);
if (jl<1) {
zs.x=X0;
zs.y=Y0;
t.stop();
} else {
var vx:Number=dx*.2;
var vy:Number=dy*.2;
zs.x+=vx;
zs.y+=vy;
}
}
//鼠标经过按钮
function jg(e:MouseEvent):void {
X0=e.target.x+25;
Y0=e.target.y-15;
t.start();
}
//鼠标按下按钮
function dj(e:MouseEvent):void {
var b:SimpleButton=e.target as SimpleButton;
url=new URLRequest(urlarray[getChildIndex(b)/2]);
navigateToURL(url);
}
相关文章
- 《无限暖暖》织衣蛛获得方法 12-26
- 《无限暖暖》美食家蜜蜂获得方法 12-26
- 《无限暖暖》泳镜蝽获得方法 12-26
- 《无限暖暖》芭蕾豆娘获得方法 12-26
- 《无限暖暖》刺绣蛾获得方法 12-26
- 《无限暖暖》尖帽仙获得方法 12-26