Publishers of technology books, eBooks, and videos for creative people

Home > Blogs > Label statements, Five ActionScript Tips in Five Days, Part 1

Label statements, Five ActionScript Tips in Five Days, Part 1

There are many little known features in ActionScript 3 that make life easier. The label statement is one of those gems that actually makes programming kind of fun.

Label statements can be assigned to loops as a reference, similar to a variable. Instead of the equal sign as the assignment operator, you use a colon between the label statement and the start of the loop.



A label statement that is assigned to a loop can later be used as a reference. For example, you can break a loop by using the break syntax followed by the label statement. In this example the artLoop label is used to break its corresponding loop when a specific piece of art is found.



Using break with a label statement makes the most sense within embedded loops because you can specify which loop to break. In this example two loops are used to search for a specific piece of art within embedded arrays.



Keep your eyes out for more ActionScript 3 tips like these each day this week.

And for more on ActionScript, be sure to check out my book ActionScript 3.0 Migration Guide, The: Making the Move from ActionScript 2.0.