# Modify code to open menu Horizontally

**URL:** <https://forum.kirupa.com/t/modify-code-to-open-menu-horizontally/242985>\
**Category:** flash\
**Created:** [November 1, 2007, 12:47pm UTC](https://forum.kirupa.com/t/modify-code-to-open-menu-horizontally/242985 "2007-11-01T12:47:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pimsme](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@pimsme](https://forum.kirupa.com/u/pimsme)\
**Post date:** [November 1, 2007, 12:47pm UTC](https://forum.kirupa.com/t/modify-code-to-open-menu-horizontally/242985/1 "2007-11-01T12:47:26Z")

</div>

## I have this code below and would like to know where and how i would alter it to have the menu reference horizontally and not vertically. I think it has something to do with “SortByVertical” and i changed it to “SortByHorizontal” but this just gave a strange result. I need to do this becuase i will be adding a scrolling text box and using it vertically does not work for the scroll bars… Thanks again for any suggestions,

var anim\_frames = 10; // Adjust speed  
var opened = null;  
var menus = [];  
FindMenus = function(){  
for (value in this){  
if (this[value] instanceof MovieClip){  
menus.push(this[value]);  
}  
}  
menus.sort(SortByVertical);  
}  
SortByVertical = function(a, b){  
return (a.\_y \> b.\_y);  
}  
ApplyMenuMask = function(i){  
var menu = menus\*;  
var mask = this.createEmptyMovieClip(“mask”+i, i);  
mask.\_x = menu.\_x;  
mask.\_y = menu.\_y;  
mask.beginFill(0,100);  
mask.moveTo(0, 0);  
mask.lineTo(menu.title.\_width, 0);  
mask.lineTo(menu.title.\_width, menu.title.\_height);  
mask.lineTo(0, menu.title.\_height);  
mask.endFill();  
menu.setMask(mask);  
menu.masker = mask;  
}  
StartMenuPosition = function(i){  
var menu = menus\*;  
if (i == 0){  
menu.\_y = menu.masker.\_y = 0;  
}else{  
var menu\_above = menus[i-1];  
menu.\_y = menu.masker.\_y = Math.round(menu\_above.\_y + menu\_above.title.\_height);  
}  
}  
MenuOpen = function(){  
var menu = this;  
menu.masker.\_height += (1+menu.\_height-menu.title.\_height)/anim\_frames;  
if (menu.masker.\_height \>= menu.\_height){  
menu.masker.\_height = menu.\_height;  
delete this.onEnterFrame;  
}  
PositionMenusBelow(menu.i);  
}  
MenuClose = function(){  
var menu = this;  
menu.masker.\_height -= (1+menu.\_height-menu.title.\_height)/anim\_frames;  
if (menu.masker.\_height \<= menu.title.\_height){  
menu.masker.\_height = menu.title.\_height;  
delete this.onEnterFrame;  
}  
PositionMenusBelow(menu.i);  
}  
TitleButtonPress = function(){  
var menu = this.\_parent;  
if (opened){  
if (opened == menu){  
menu.onEnterFrame = MenuClose;  
opened = null;  
}else{  
opened.onEnterFrame = MenuClose;  
menu.onEnterFrame = MenuOpen;  
opened = menu;  
}  
}else{  
menu.onEnterFrame = MenuOpen;  
opened = menu;  
}  
}  
PositionMenusBelow = function(i){  
var menu = menus\*;  
if (i \< menus.length-1){  
var menu\_below = menus[i+1];  
for (i=i+1; i\<menus.length; i++){  
if (menus\* == menu\_below){  
menus\*.\_y = menus\*.masker.\_y = menu.\_y + menu.masker.\_height;  
}else{  
var menu\_above = menus[i-1];  
menus\*.\_y = menus\*.masker.\_y = menu\_above.\_y + menu\_above.masker.\_height;  
}  
}  
}  
}  
Init = function(){  
FindMenus();  
for (var i=0; i\<menus.length; i++){  
menus\*.i = i;  
ApplyMenuMask(i);  
StartMenuPosition(i);  
menus\*.title.onPress = TitleButtonPress;  
}  
}  
Init();

* * *
