# My colapsing menu need to be already open

**URL:** <https://forum.kirupa.com/t/my-colapsing-menu-need-to-be-already-open/217635>\
**Category:** Uncategorized\
**Created:** [February 28, 2007, 3:46pm UTC](https://forum.kirupa.com/t/my-colapsing-menu-need-to-be-already-open/217635 "2007-02-28T15:46:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikiwaka](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@rikiwaka](https://forum.kirupa.com/u/rikiwaka)\
**Post date:** [February 28, 2007, 3:46pm UTC](https://forum.kirupa.com/t/my-colapsing-menu-need-to-be-already-open/217635/1 "2007-02-28T15:46:45Z")

</div>

hi there !

i have a collapsing menu (coming from senocular… thanks a lot senoc’!!!) and i would like to get it already open when we arrive on the page …

does someone knows how to do ?

here is the code :

// Variables  
var speed = 10; // constant speed for menu opening and closing  
var opened = null; // variable to determine which menu is currently opened  
var menus = []; // array to store all menu items

// FindMenus: finds movieclips within this movieclip and adds them to  
// the menus array. Only place menu clips within this clip otherwise  
// this function will assume the non-menu clips to be clips as well  
FindMenus = function(){  
for (value in this){  
if (this[value] instanceof MovieClip){  
menus.push(this[value]);  
}  
}  
menus.sort(SortByVertical); // order so the highest is first  
}  
// SortByVertical: sort function to sort menus in menus array  
// so that the highest menu appears first  
SortByVertical = function(a, b){  
return (a.\_y \> b.\_y);  
}

// ApplyMenuMask: creates and draws a function for the i’th menu  
// in the menus array. That menu clips is then assigned a  
// property “masker” representing this clip  
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: positions the menu to start. This is its closed  
// position beneath the menu above it unless its the first menu where its 0.  
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: this function opens a menu when its title is clicked  
MenuOpen = function(){  
var menu = this;  
menu.masker.\_height += speed;  
if (menu.masker.\_height \>= menu.\_height){  
menu.masker.\_height = menu.\_height;  
delete this.onEnterFrame;  
}  
PositionMenusBelow(menu.i);  
}

// MenuClose: this function closes a menu when its title is clicked  
// When a menu has closed, its onClose callback is called (then deleted)  
MenuClose = function(){  
var menu = this;  
if (speed \>= menu.masker.\_height) menu.masker.\_height = menu.title.\_height;  
else menu.masker.\_height -= speed;  
if (menu.masker.\_height \<= menu.title.\_height){  
menu.masker.\_height = menu.title.\_height;  
opened = null;  
menu.onClose();  
delete menu.onClose;  
delete this.onEnterFrame;  
}  
PositionMenusBelow(menu.i);  
}  
// TitleButtonPress: this is the action assigned to a titlebar onRelease in a menu  
// based on that menu’s status; whether its open or closed and if anything is open  
// at all to begin with (if there is, the open menu would need to close first)  
TitleButtonPress = function(){  
var menu = this.\_parent;  
if (opened){  
if (opened == menu){  
menu.onEnterFrame = MenuClose;  
}else{  
opened.onClose = function(){  
menu.onEnterFrame = MenuOpen;  
opened = menu;  
}  
opened.onEnterFrame = MenuClose;  
}  
}else{ // nothing opened  
menu.onEnterFrame = MenuOpen;  
opened = menu;  
}  
}  
// PositionMenusBelow: Positions all menus below the i’th menu based on that  
// menus mask. This is used when opening or closing a menu so that menu items  
// beneath update their position properly  
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;  
}  
}  
}   
}

// Initialization function. Does setup operations  
Init = function(){  
FindMenus(); // find movieclips within this movieclip and assign to menus array  
// for each menu (as in menus array)  
for (var i=0; i\<menus.length; i++){  
menus\*.i = i; // assign a number to represent its position in the array  
ApplyMenuMask(i); // give it a mask  
StartMenuPosition(i); // position it accordingly (vertical only)  
menus\*.title.onPress = TitleButtonPress; // apply the actions to the titlebar  
}  
}  
Init();
