Manipulate multiple objects with less Actionscript 3.0 code

Manipulate multiple objects with less Actionscript 3.0 code

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:

thelongway

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.

shortway

About the Author

Lode is a Creative-Geek with passion for Graphic design , he is also into the web programming "stuff" like Adobe Flash,air and Flex . Lode loves to learn and loves to share knowledge with others.Follow Lode on http://twitter.com/stealfish