Is there a better way to set up a flash project with lots of navigation than having to do this?:
bottomNav.contact_btn.addEventListener(MouseEvent.CLICK, changeContent);
bottomNav.portfolio_btn.addEventListener(MouseEvent.CLICK, changeContent);
bottomNav.news_btn.addEventListener(MouseEvent.CLICK, changeContent);
bottomNav.inspiration_btn.addEventListener(MouseEvent.CLICK, changeContent);
bottomNav.home_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.about_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.services_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.home_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.inspiration_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.inspiration_archive_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.portfolio_showcase_btn.addEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.portfolio_archive_btn.addEventListener(MouseEvent.CLICK, changeContent);
and if not, there are always moments between animations where the last thing you want to happen is for someone to click a button and have another function fire off in the middle of your beautiful wipe between two scenes. You end up with (or at least I do) countless errors and a pissed off client.
What do you do to suspend all of those listeners without adding a function to the end of every other function to temporarily disable them?
Please, if someone has the magic practice, I’d love to hear it.
in regards to how I do it I’ve been writing something like this:
function suspendBtns():void
{
secondaryNav.inspiration_archive_btn.removeEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.portfolio_showcase_btn.removeEventListener(MouseEvent.CLICK, changeContent);
secondaryNav.portfolio_archive_btn.removeEventListener(MouseEvent.CLICK, changeContent);
}
and would add suspendBtns(); to the end of every function that would transition between clips.
then obviously another function called enactBtns() or something like that.
I tried once just adding one event listener to the stage:
stage.addEventListner(MouseEvent.CLICK, doFunction);
and then the function would find the name of the btn like:
function doFunction(e:Event):void{
switch(e.target.name){
case"home_btn":
doThis();
break;
case"away_btn":
doThat();
break;
}
}
and so on. That didn’t work so well, it felt as though I had to click every button twice to get it to work.
And I still had to suspend the event listener in between actions.
An alternative to removing listeners, to temporally disable buttons, like in the suspendBtns example function above, is to set mouseEnabled to false.
so instead of:
… you would have:
That way, the suspendBtns function won’t need to know what listeners to remove, and correspondingly to be added again when the buttons are to be enabled again. It will also disable other MouseEvent’s, like MOUSE_OVER and so on.
And I’d also recommend storing the buttons in an array, as suggested by Allan and Tahir.