Dropdown menus
Code Actionscript 2.0
Frame action
for (column = 0; column <= 3; column = column + 1) {
menu.duplicateMovieClip("menu" + column, column);
_root["menu" + column]._x = 4 + column * 98;
_root["menu" + column]._y = 20;
}
Instance action
onClipEvent (load) {
this._alpha = 100;
}
on (rollOver) {
this._alpha = 30;
}
on (rollOut) {
this._alpha = 100;
}
on (press) {
for (row = 1; row < 6; row = row + 1) {
_parent.submenu.duplicateMovieClip("submenu" + row, row + 100);
_parent["submenu" + row]._y = this._y + row * 20;
_parent["submenu" + row]._x = this._x;
}
}
Instance action
onClipEvent (load) {
this._alpha = 100;
}
on (rollOver) {
this._alpha = 30;
}
on (rollOut) {
this._alpha = 100;
}
Code Actionscript 3.0
var Submenus:Array = new Array(); var Menus:Array = new Array(); for (var column = 0; column <= 3; column = column + 1) { //important: menu has to be exported for actionscript //go to "linkage" in library menu Menus[column] = new menuObject(); Menus[column].x = 4 + column * 98; Menus[column].y = 20; Menus[column].alpha = 1; Menus[column].addEventListener(MouseEvent.MOUSE_OVER, rollOver); Menus[column].addEventListener(MouseEvent.MOUSE_OUT, rollOut); Menus[column].addEventListener(MouseEvent.MOUSE_DOWN, press); addChild(Menus[column]); } for (var row = 1; row < 6; row = row + 1) { Submenus[row] = new submenuObject(); Submenus[row].y = 20 + row * 20; Submenus[row].x= 4; Submenus[row].name = "submenu"+row; Submenus[row].addEventListener(MouseEvent.MOUSE_OVER, rollOver); Submenus[row].addEventListener(MouseEvent.MOUSE_OUT, rollOut); Submenus[row].visible = false; addChild(Submenus[row]); } function rollOver(e:MouseEvent) { e.target.alpha = 0.3; } function rollOut(e:MouseEvent) { e.target.alpha = 1; } function press(e:MouseEvent) { for (var row = 1; row < 6; row = row + 1) { Submenus[row].x=e.target.x; Submenus[row].visible = true; } }
Description
This script generates a menu with dropdowns as submenus. In Actionscript 2, the frame-action generates the main menu; and the instance-action menu makes every button in the main menu generate its given submenu. In Actionscript 3, menus und submenus are generated with the two for-loops.
related to:
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File