all groups > flash actionscript > june 2006 >
You're in the

flash actionscript

group:

Buttons only respond once


Buttons only respond once ricklecoat
6/28/2006 9:46:15 PM
flash actionscript:
I've got a half dozen buttons (all instances of the same symbol). I had them
working fine except that they lacked that 'locked' state -- you know, where the
button remains in an 'over' or otherwise highlighted state to show the use
which part of the site they are in. So I added some code to sort that out,
using the 'button_mc.gotoAndStop("activeStateKeyframe")' technique. I also
included some code intended to record the button that had been clicked as a
variable, pass that info into the function as part of the above Goto target
path, and then reuse the variable to determine which buttons had NOT been
clicked and set their states back to the default 'off' state.

Each button calls two functions; the first one deals with other stuff and
works perfectly; the second is the that described above. With just the first
function in place, all was well. However, once I introduced the second
function, called lockButton, the buttons would behave exactly as intended on
the first click but then would not respond to subsequent mouse clicks. It's
definitely the second function that is giving the problems because if I remove
it from the sequence (the end of the first function contains a call to the
second, in a daisy-chain sort of way) the buttons respond normally again --
albeit without the required "You are here" state.

I'll attach the relevant code to see if anyone can help; my apologies for what
is bound to be awful, inefficient code, but I'm really new to this (typed my
first line of Actionscript 4 days ago). Anyway, here's the code. I've included
the first function for completeness, as that is the one that the buttons call
directly.

Thanks in advance for any help you can offer an AS newbie.



// MAINCLICK
// When a main button is clicked, this function resolves whether subsections
should open, close, or remain as they are.
function mainClick() {
// This bit handles the Products button
if (buttonChoice == "products_mc") {
if (productsOpen == false, servicesOpen == true) {
navig_mc.gotoAndPlay("closeServices");
} else if (servicesOpen == false, productsOpen == false) {
navig_mc.gotoAndPlay("openProducts");
} else {
navig_mc.stop();
}
// This bit handles the Services button
} else if (buttonChoice == "services_mc") {
if (servicesOpen == false, productsOpen == true) {
navig_mc.gotoAndPlay("closeProducts");
} else if (productsOpen == false, servicesOpen == false) {
navig_mc.gotoAndPlay("openServices");
} else {
navig_mc.stop();
}
// This bit handles the other buttons
} else {
if (servicesOpen == true) {
navig_mc.gotoAndPlay("closeServices");
} else if (productsOpen == true) {
navig_mc.gotoAndPlay("closeProducts");
} else {
navig_mc.gotoAndStop("normalState");
}
}
lockButton();
}


//SET BUTTON'S 'LOCKED STATE
// This sets the 'currently active' state for the button
function lockButton() {
// Set current button
navig_mc[buttonChoice].gotoAndStop(2);
// Cancel previous button
if (buttonChoice != "home_mc") {
navig_mc.home_mc.gotoAndStop(1);
}
if (buttonChoice != "products_mc") {
navig_mc.products_mc.gotoAndStop(1);
}
if (buttonChoice != "services_mc") {
navig_mc.services_mc.gotoAndStop(1);
}
if (buttonChoice != "team_mc") {
navig_mc.team_mc.gotoAndStop(1);
}
if (buttonChoice != "smile_mc") {
navig_mc.smile_mc.gotoAndStop(1);
}
if (buttonChoice != "contact_mc") {
navig_mc.contact_mc.gotoAndStop(1);
}
if (buttonChoice != "surgeons_mc") {
navig_mc.surgeons_mc.gotoAndStop(1);
}
}


// MAIN BUTTONS
// Event handlers for HOME button
navig_mc.home_mc.theButton_btn.onRelease = function() {
buttonChoice = "home_mc";
mainClick();
test_txt.text = buttonChoice;
};
// Event handlers for PRODUCTS button
navig_mc.products_mc.theButton_btn.onRelease = function() {
buttonChoice = "products_mc";
mainClick();
test_txt.text = buttonChoice;
};
Re: Buttons only respond once ricklecoat
6/29/2006 12:00:00 AM
::bump::

I know it looks like a huge slab of code to look at, but it's really just two
functions and the button event handler that calls them.
If anybody has any insight into this problem I'd really appreciate it, because
it's holding up the rest of the project.

Many thanks in advance;
AddThis Social Bookmark Button