Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : need help with rollovers


deadlast007
2/10/2006 8:13:22 PM
I am using the following script in my actions to run my title, but if i convert
the title to a button menu wont work at all. any ideas?

::::// Variables
var speedo = 20; // constant speed for menu opening
var speedc = 40; // constant speed for menu closing
var opened = null; // variable to determine which menu is currently
opened
var menus = ; // array to store all menu items


FindMenus = function(){
for (value in this){
if (this instanceof MovieClip){
menus.push(this);
}
}
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;
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.title.textColor = 0;
menu.masker._height += speedo;
if (menu.masker._height >= menu._height){
menu.masker._height = menu._height;
delete this.onEnterFrame;
}
PositionMenusBelow(menu.i);
}


MenuClose = function(){
var menu = this;
if (speedc >= menu.masker._height) menu.masker._height =
menu.title._height;
else menu.masker._height -= speedc;
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 = 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{
menu.onEnterFrame = MenuOpen;
opened = menu;
}
}


PositionMenusBelow = function(i){
var menu = menus;
if (i < menus.length-1){
var menu_below = menus;
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;
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();

zensoldier
2/10/2006 10:30:03 PM
little too tired to dig through your code but in generally, buttons = bad

I don't use them. Clips only. Most of my stuff is dynamic and buttons can't
really do very much. Convert them to MCs and forget they ever existed:-)
AddThis Social Bookmark Button