PDA

View Full Version : Cool Menu Alpha RollOver Needs Tweaking!


kingkahuna
07-10-2005, 06:28 AM
I have AS controlling the alpha of each image of a menu. Each image is a Graphic embedded within it's own MovieClip. Using onEnterFrame, RollOver of one MC fades the alpha of the other MCs from 100 to 35, and RollOut brings them back up. As onEnterFrame is a continuous function, the menu images fade more and more each time I rollOver another menu until they disappear! They're supposed to stop at 35!

What AS can I use to stop this continuous fading to zero alpha - I'm guessing it's a conditional - something like, "if the MC is <35, stop fading". Any ideas how I can script this?

Here is the script. I've shortened it to 3 of the 9 menu images, named navyoMC, visionMC and musicMC. I've also included the zipped .fla file.


// NAVYO ROLLOVER FADE DOWN MENU
navyoMC._alpha = 100;
navyoMC.onRollOver = function() {
visionMC.onEnterFrame = function() {
this._alpha -= 20;
if (this._alpha<35) {
delete this.onEnterFrame;
}
};
musicMC.onEnterFrame = function() {
this._alpha -=20
if (this._alpha<35) {
delete this.onEnterFrame;
}
};
};
// NAVYO ROLLOUT FADE UP MENU
navyoMC.onRollOut = function() {
visionMC.onEnterFrame = function() {
this._alpha += 20;
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
musicMC.onEnterFrame = function() {
this._alpha +=20
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
};
// VISION ROLLOVER FADE DOWN MENU
visionMC._alpha = 100;
visionMC.onRollOver = function() {
navyoMC.onEnterFrame = function() {
this._alpha -= 20;
if (this._alpha<35) {
delete this.onEnterFrame;
}
};
musicMC.onEnterFrame = function() {
this._alpha -=20
if (this._alpha<35) {
delete this.onEnterFrame;
}
};
};
// VISION ROLLOUT FADE UP MENU
visionMC.onRollOut = function() {
navyoMC.onEnterFrame = function() {
this._alpha += 20;
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
musicMC.onEnterFrame = function() {
this._alpha +=20
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
};
// MUSIC ROLLOVER FADE DOWN MENU
musicMC._alpha = 100;
musicMC.onRollOver = function() {
visionMC.onEnterFrame = function() {
this._alpha -= 20;
if (this._alpha<35) {
delete this.onEnterFrame;
}
};
navyoMC.onEnterFrame = function() {
this._alpha -=20
if (this._alpha<35) {
delete this.onEnterFrame;
}
};
};
// MUSIC ROLLOUT FADE UP MENU
musicMC.onRollOut = function() {
visionMC.onEnterFrame = function() {
this._alpha += 20;
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
navyoMC.onEnterFrame = function() {
this._alpha +=20
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
};
[B]

pixelwit
07-10-2005, 03:12 PM
//
// An Array to store references to all your buttons.
var allButtons = [navyoMC, visionMC, musicMC];
//
// Function to fade UP a clip's alpha.
function fadeUp(){
with(this){
_alpha += 20
if(_alpha > 100) {
_alpha = 100;
delete onEnterFrame;
}
}
}
//
// Function o fade DOWN a clip's alpha.
function fadeDown(){
with(this){
_alpha -= 20
if(_alpha < 35) {
_alpha = 35;
delete onEnterFrame;
}
}
}
//
// One RollOver function shared by every button.
function myRollOver(){
for(var i in allButtons){
allButtons[i].onEnterFrame = fadeDown;
}
this.onEnterFrame = fadeUp;
}
//
// One RollOut function shared by every button.
function myRollOut(){
for(var i in allButtons){
allButtons[i].onEnterFrame = fadeUp;
}
}
//
// Assign RollOver and RollOut functions to all buttons.
for(var i in allButtons){
var buttn = allButtons[i];
buttn.onRollOver = myRollOver;
buttn.onRollOut = myRollOut;
buttn.onReleaseOutside = myRollOut;
}
//-PiXELWiT
http://www.pixelwit.com

kingkahuna
07-11-2005, 06:59 AM
A bit of advanced AS - just what I needed. Works perfectly. And from the boss, too!

pixelwit
07-11-2005, 02:56 PM
You're welcome.

-PiXELWiT
http://www.pixelwit.com

Bufffy
07-30-2005, 09:15 AM
Hey guys. I really like the compactness of this script. But I was wondering how I could write it for say, 2 menus(well 1 menu and a set of images below) then when a menu item is rolled over, the appropriate image highlights along with it. I was thinking of making another array and then perhaps comparing the two once the one was called with an if statement for i. But I'm sure I'm way off.

kingkahuna
07-30-2005, 11:07 PM
You'll have to get PiXELWiT (or someone) on this one. I'm still new at this.... kk