As3.0 navigation bar menu instance

Source: Internet
Author: User
Tags addchild


Code:

Set frame speed
Stage.framerate=30
Declare some variables
var namearray:array=new Array ("Flash bar", "Anime", "textbook", "Material", "forum");
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;
Create a button
For (k=0 k<namearray.length; k++) {
Btn=new SimpleButton ();
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;
}
button to indicate
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);
The coordinate settings indicated by the button
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;
}
}
Mouse over button
function JG (e:mouseevent): void {
x0=e.target.x+25;
y0=e.target.y-15;
T.start ();
}
Press the mouse button
function DJ (e:mouseevent): void {
var b:simplebutton=e.target as SimpleButton;
Url=new URLRequest (Urlarray[getchildindex (b)/2]);
Navigatetourl (URL);
}

For more tutorials, please go to www.111cn.net/flash_a/flash.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.