Menu Final Effect preview:
Source and its resolution:
The menu directly with AS, the function is very few, the color block will move with the mouse movement.
The following is the main program.
var menutext = new Array ("My collection of pictures", "My Collection of Music", "My personal works",
"I want to see the diary", "Now write to Me", "Into my book");
The label for the menu.
var menuurl = new Array ("http://#", "http://#", "http://#", "http://#",
"qxiao_xi@tom.com", "http://ningning.dns0755.net");
The URL to which the menu label points.
var Theitem;
This variable is used when building the MC.
var i;
Loop variable.
var step;
The number of steps that the color block moves.
var running;
A variable that determines whether to move.
Create a new function. The reference can be directly used This.drawrect (X,Y,W,H);
x,y--> coordinate value,w,h--> width and height.
MovieClip.prototype.DrawRect = function (x, Y, W, h) {
This.moveto (x, y);
This.lineto (x+w, y);
This.lineto (X+w, y+h);
This.lineto (x, Y+h)
This.lineto (x, y);
};
A function that establishes the purpose of a menu item.
mc--> Movie Clip x,y--> coordinates w,h--> wide, high. Text--> string.
function CreateItem (MC, X, Y, W, h, text) {
Mc.createtextfield ("Text", 2, X+10, Y, 85, 20);
Create an empty dynamic text segment
Mc.text.text = text;
Assign a value to a new dynamic text segment, color,
Mc.text.textColor = 0x000000
Text size has no border, can be selected.
Mc.text.size = 14;
Mc.text.border = false;
Mc.text.selectable = false;
}
The function to start creating the menu.
function CreateMenu (MC) {
Create a movie clip and put a color block on it. The name is Bg-->background.
Mc.createemptymovieclip ("BG", 1);
Create an empty MC
Mc.bg.beginFill (0X33CCFF, 100);
Start padding
Mc.bg.DrawRect (0, 0, 90, 20);
Call function
Mc.bg.endFill ();
End Fill
Mc.bg._alpha = 50;
Transparency
Mc.bg._visible = false;
Visibility of
Finish painting.
Start the loop below.
for (i=0 I
Mc.createemptymovieclip ("Item" +i, 2+i);
Theitem = mc["item" +i];
Theitem.index = i;
CreateItem (Theitem, i*90, 0, menutext[i]);
The action at the beginning of the frame.
Theitem.onenterframe = function () {
The default judgment condition for an if statement is "true"
When Running==true.
if (running) {
if (mc.bg._x<=step*90) {
Mc.bg._x + 5;
else if (mc.bg._x>=step*90+10) {
Mc.bg._x-= 5;
}
}
};
The act of passing.
Theitem.onrollover = function () {
Mc.bg._visible = true;
running = true;
Step = This.index;
};
The act of leaving.
Theitem.onrollout = function () {
Mc.bg._visible = false;
running = false;
};
The action when clicked.
theitem.onpress = function () {
GetURL (Menuurl[this.index]);
};
}
Loop end.
}
Createemptymovieclip ("menu", 10);
Create a menu movie clip.
menu._y = 0;
The coordinate value.
menu._x = 0;
CreateMenu (menu);
Create a menu.
Put this program in the first frame of the scene and run it.
It took me a morning to write something.