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 can use loops for any of the following many of which would be difficult or impossible to perform without them:

  • To create dynamically generated drop-down lists

  • To validate data

  • To search text

  • To dynamically duplicate movie clips

  • To copy the contents of one array to a new array

  • To detect collisions in games between projectiles and objects

You can use loops to automate any number of tasks. Take, for example, dynamically creating movie clip instances: If your project called for 100 instances of the same movie clip (spaced evenly), you could drag one instance from the library and create a four-or five-line looping statement to automatically duplicate the instance 100 times and position those duplicates on the stage a great improvement over dragging 100 instances from the library and then aligning each and every one. What's more, you can modify your looping statement to use it various ways in your project.


Loops are also dynamic. Suppose you scripted a loop to dynamically create a menu of 15 choices (buttons). By altering the loop slightly, you could easily add and remove choices dynamically. In contrast, adding or removing a button from a manually created menu involves adding or removing the choice, then moving all of the other choices up or down one perhaps even rescripting here and there.

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

Macromedia Flash MX ActionScripting Advanced. Training from the Source
Macromedia Flash MX ActionScripting: Advanced Training from the Source
ISBN: 0201770229
EAN: 2147483647
Year: 2002
Pages: 161

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