# How can I do this better?

**URL:** <https://forum.kirupa.com/t/how-can-i-do-this-better/258105>\
**Category:** flash\
**Created:** [April 21, 2008, 12:55am UTC](https://forum.kirupa.com/t/how-can-i-do-this-better/258105 "2008-04-21T00:55:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nineteen](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nineteen/32/2679_2.png) [@Nineteen](https://forum.kirupa.com/u/Nineteen)\
**Post date:** [April 21, 2008, 12:55am UTC](https://forum.kirupa.com/t/how-can-i-do-this-better/258105/1 "2008-04-21T00:55:18Z")

</div>

Hi,

I’ve written a dynamic nav and need a better way to check if all the nav items are moused out.

Basically when a nav item is made it is given a mouse out and mouse in.  
When you mouse in it sets a value of ‘0’ in an array and moused out is set a value of ‘1’.

There is then this piece of code  
ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#808080]_//Listen and Move_[/COLOR]  
mcNavOutTest.[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR]:[COLOR=#0000FF]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
nCounterToFade = [COLOR=#000080]0[/COLOR];  
[COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] r:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]0[/COLOR]; r \< arClosed.[COLOR=#0000FF]length[/COLOR]; r++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
nCounterToFade += arClosed[COLOR=#000000][[/COLOR]r[COLOR=#000000]][/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR];  
[/LEFT]  
[/FONT]

That adds all the values of the array together. When you mouse out a nav it tests to see if ‘nCounterToFade’ is equal to the length of the array (meaning all values of the array are 1 = all nav items are moused out).

I think its really bad to have a for loop being constantly tested with an onenterframe event. How can I make this better / test if all nav items are moused out. It would have been ideal to create some sort of if statement that checks all nav items but I don’t know how to do this dynamically.

Please help 🙂

Cheers,  
Ryan
