Often, I am looking for ways to do things faster and more effecient
Here is a thing that I would like to share with you. If you are creating a navigation bar for example, you need
to assign event listeners to each element in the navigation bar. This takes 3 rules per item or more…
the code would look somethings like this:
this approach is correct but as you can see it takes 20 lines of code to accomplish an action that you can perform in just 5 lines!
How?
by using the for each loop. The for each loop enables you to look at each element in the given element. So why shouldn’t you use it on a smart way? The code becomes more readable by using this approach and easier to maintain.
just make a simple for each loop who loops through every movieclip in the given element, and adjust the parameters to your wishes as shown below.
Also interesting reads:


Hi,
That would give them all the same characteristic of on mouse over and mouse out…, but what if I want to modify each button’s position? as they’re all called mov, is there a way I can access each specific button? because for the code in 20 lines you can say well
container.resumeButton.x = 20; and so on… so if you have them inside the for each form… how can you access them?
Thanks in advance