Why Loops Are Useful


Loops enable Flash to perform an action (or set of actions) repeatedly, which means that with just a few lines of ActionScript, you can force an action to be executed several thousand times. In ActionScript, you use loops for tasks that would be difficult or impossible without loops. For example:

  • Creating dynamically generated drop-down lists

  • Validating data

  • Searching text

  • Dynamically duplicating movie clips

  • Copying the contents of one array to a new array

You can use loops to automate any number of tasks, such as dynamically creating MovieClip instances. Suppose that your project called for 100 evenly spaced instances of the same MovieClip. You could create a four- or five-line looping statement to attach a MovieClip from your library 100 times and position each clip on the Stage automaticallya great improvement over dragging 100 instances from the library and aligning each one manually.

Loops are also dynamic. Suppose that you scripted a loop to create a menu of 15 choices (buttons) dynamically. By altering the loop slightly, you could add and remove choices dynamically. This would be impossible to do without loops.

As you progress through this lesson (and the rest of the book), you'll see the value of using loops in your scripts.




Macromedia Flash 8 ActionScript Training from the Source
Macromedia Flash 8 ActionScript: Training from the Source
ISBN: 0321336194
EAN: 2147483647
Year: 2007
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net