Using Booleans to Manage State I'm in the middle of writing my own little bullet shooter game much in the style of Touhou. Everything works fine so far but I'm disliking certain aspects of my code. Take this function for showing and unshowing the title screen:

    private function runIntro() : void
    {
        if (introFadeInTitle_ &amp;&amp; aliceIntroTxt.alpha &lt; 1)
            aliceIntroTxt.alpha += 0.02;
        else if (introFadeInTitle_)
        {
            var timer : Timer = new Timer(1000);
            timer.addEventListener(TimerEvent.TIMER, function() {
                timer.stop();

                introFadeInBtns_  = true;
            });
            timer.start();

            introFadeInTitle_ = false;
        } 
        else if (introFadeInBtns_ &amp;&amp; startBtn.alpha &lt; 1)
        {
            startBtn.alpha   += 0.02;
            optionsBtn.alpha += 0.02;
        }
        else if (introFadeInBtns_)
        {
            introFadeInBtns_ = false;

            gameState = GameState.READY;
        }

        if (introFadeOutBtns_ &amp;&amp; startBtn.alpha &gt; 0)
        {
            startBtn.alpha   -= 0.02;
            optionsBtn.alpha -= 0.02;
        }
        else if (introFadeOutBtns_)
        {
            var timer : Timer = new Timer(500);
            timer.addEventListener(TimerEvent.TIMER, function() {
                timer.stop();

                introFadeOutTitle_ = true;
            });
            timer.start();

            introFadeOutBtns_ = false;
        }
        else if (introFadeOutTitle_ &amp;&amp; aliceIntroTxt.alpha &gt; 0)
            aliceIntroTxt.alpha -= 0.02;
        else if (introFadeOutTitle_)
        {
            var timer : Timer = new Timer(500);
            timer.addEventListener(TimerEvent.TIMER, function() {
                timer.stop();

                introFadeOutBg_ = true;
            });
            timer.start();

            introFadeOutTitle_ = false;
        } 
        else if (introFadeOutBg_ &amp;&amp; introBg.alpha &gt; 0)
            introBg.alpha -= 0.02;
        else if (introFadeOutBg_)
        {
            introFadeOutBg_;

            gameState = GameState.RUNNING;
        }
    }


At a glance, it's just a bunch of if-else-if statements that check whether or not a given object has faded out and what the current state of the animation is. I feel that this if-else-if chain is alright for a rather short function like this, but I do have more complicated states that I wish to show (for example a ready-set-go splash before the fight begins) that would just balloon this kind of structure into an unholy mess.

What is the best way to deal with this code?
If ActionScript supports enums use an enum instead of the many booleans. If not, use a string with one constant for every state. It's also better than the booleans. For example:

...
else if (state == FADE_INT_ASDF) {
   state = CODE_OF_NEXT_STATE;
   gameState = GameState.READY;
}
...


If the logic was more complicated it would be worth implementing the State pattern.



If the booleans were replaced to an enum/string constants you can create a new setTimer function which could remove some code duplication:

private function setTimer(int timeout, IntroState/String newState) : void {
    var timer : Timer = new Timer(timeout);
    timer.addEventListener(TimerEvent.TIMER, function() {
        timer.stop();
        state = newState;
    });
    timer.start();
}