# Help optimize code

**URL:** <https://forum.kirupa.com/t/help-optimize-code/231676>\
**Category:** flash\
**Created:** [July 6, 2007, 3:40pm UTC](https://forum.kirupa.com/t/help-optimize-code/231676 "2007-07-06T15:40:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekoer](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@tekoer](https://forum.kirupa.com/u/tekoer)\
**Post date:** [July 6, 2007, 3:40pm UTC](https://forum.kirupa.com/t/help-optimize-code/231676/1 "2007-07-06T15:40:05Z")

</div>

Hey, now i’ve got a code that looks like this:

```auto
b_1.btn_bg.onRelease = function(){
	if(_root.currMovie == "case"){
	b_1.btn_bg.enabled = false;
	b_2.btn_bg.enabled = true;
	b_2.initialState();
}

b_2.btn_bg.onRelease = function(){
	if(_root.currMovie == "case2"){
	b_2.btn_bg.enabled = false;
	b_1.btn_bg.enabled = true;
	b_1.initialState();
	
}

```

What it does is to check if the loaded movie is case1 etc…Then disables the b\_1, enables  
b\_2 button, and runs initialState(); for each button enabled button.

I will have about 5 buttons, and it would be pretty much code to enable every button, and run initialState. How would you optimize it?
