• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Creating Loops

Loops allow Flash to perform an action repeatedly. You can use a loop to create a dynamic drop-down menu, validate data, search for text, duplicate movie clips, and even to detect collisions in games that have projectiles and objects. Conditional statements let you execute an action based on a specific condition. You can have a specific action continue to loop until a certain condition was met. For example, continue to search for a specific text string until it is found, or the end of the text document is reached. Loops come in two forms—While loops and For loops—it doesn't matter what type of loop is chosen, they will both require a conditional statement to start and stop the loop.

  • While Loops. While loops continue to execute while a certain condition exists (keep looping or searching) until the specific value is reached.

    i = 4;
    while (var i > 0) {
      my_mc.duplicateMovieClip("newMC" + i, i );
      i--;
    }
    
  • For Loops. For loops are self-contained counters. For example, loop (repeat the action), ten times, and then stop.

    on (release) {
      for (x=0; x<=10, ++x);
      myClip.duplicateMovieClip ("myClip" + x, x);
      myClip._rotation =45 + x * 10;
      }
    }
    

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint