Can this code be simplified?

Hi there,

I’ve got two problems. 1 - I think the code I am using needs to be simplified to use one function but I’m not sure how to do it. I have 9 buttons that each correspond to a block of text which is invisible. When the button is pressed, the text block (movie clip) shows up/fades in using the tween class. This works to a point (until you click too fast, but that’s problem two) but the code is too heavy - take a look at this block:


var active:MovieClip; // our default active textbox nothing

specIntTextBox_btn.onRelease = function () {
    if (active != null) {
        var fadeOut:Tween = new Tween(active, "_alpha", Elastic.easeOut, 100, 0, 6, true);
    }
    var fadeIn:Tween = new Tween(specIntTextBox, "_alpha", Elastic.easeOut, 0, 100, 9, true);
    active = specIntTextBox;
}

custReqTextBox_btn.onRelease = function () {
    if (active != null) {
        var fadeOut:Tween = new Tween(active, "_alpha", Elastic.easeOut, 100, 0, 6, true);
    }
    var fadeIn:Tween = new Tween(custReqTextBox, "_alpha", Elastic.easeOut, 0, 100, 9, true);
    active = custReqTextBox;
}

// etc, 7 more blocks like that.

That is 2 of 9 blocks. As you can see they all do the same thing. I know how I’d do this in JavaScript but not sure how to handle it in ActionScript. I’d rather have every single button fire off the same function, and have the button know somehow what text box to show. Then I would not have to repeat this block 9 times.

The other problem is that if you click too quickly then you start getting multiple boxes showing up and it all gets screwed up. There must be a way to avoid this, but I am not sure how.

You can see this page at

http://dev2.pixelmech.com/access/access.php

Click on the left side stack of sources to get to the section I am talking about, then click on of the boxes. You have to click pretty quick on the blocks to see the problem with the text boxes.

Any help is surely appreciated.

Thanks!

Tom