Why Loops Are Useful

Chia sẻ: Qweqwdasd Qweqdasda | Ngày: | Loại File: PDF | Số trang:2

lượt xem

Why Loops Are Useful

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Flash cho phép các vòng lặp để thực hiện một hành động (hoặc thiết lập các hành động) nhiều lần, có nghĩa là chỉ với một vài dòng ActionScript, bạn có thể lực một hành động được thực hiện vài nghìn lần. Trong ActionScript, bạn sử dụng các vòng lặp cho các nhiệm vụ mà có thể khó hoặc không thể không có vòng.

Chủ đề:

Nội dung Text: Why Loops Are Useful

  1. < Day Day Up > 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 • Detecting collisions in games between projectiles and objects You can use loops to automate any number of tasks, such as dynamically creating movie clip instances. Suppose your project called for 100 evenly spaced instances of the same movie clip. You could drag one instance from the library and then create a four- or five- line looping statement to duplicate the instance 100 times and position each duplicate on the stage automatically—a great improvement over dragging 100 instances from the library and aligning each one manually. Loops are also dynamic. Suppose 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. In contrast, adding or removing a button from a manually created menu involves adding or removing the choice and then moving all of the other choices up or down one position, and perhaps even rescripting here and there.
  2. As you progress through this lesson (and the rest of the book), you'll see the value of using loops in your scripts. < Day Day Up >  
Đồng bộ tài khoản