Download
repetition n.
Skip this Video
Loading SlideShow in 5 Seconds..
Repetition PowerPoint Presentation

Repetition

70 Views Download Presentation
Download Presentation

Repetition

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Repetition

  2. Objectives of this topic: You can … Write a conditional statement in ActionScript Create more interactive applications Create a loop in AS3

  3. Overview This topic covers • Loops • Creating a Code Loop • Using a Loop to Generate Instances of a Class • Placing Instances Created by a Loop

  4. Loops • A loop is a function in AS that runs as many times as you specify • A loop allows the designer to control exactly how many times the function runs • easily to go back and make a simple change to AS • Loops are powerful tools that make repetitive tasks, which would be monotonous in design mode

  5. Creating a Code Loop • Create a variable or placeholder, that is the data type Number to stands as index in loops Example: var i:Number = 0; • The initial value of this variable is to be 0 (zero) • The index is the number of times the loop will run

  6. Loop has a condition – means the loop will run as long as it less then certain times Example: i < 20;  the loop will run as long as I less than 20

  7. Use mathematical operator to increase the value of a variable Example: i++;  means the value of i variable will increase by for every time the code runs - first time, i will equal to 0 - second time, i will equal to 1 and so on, all the way up to 19

  8. for(var i:Number =0; i < 20; i++) { trace(i); } (Flash: Loops) • telling Flash that every time the codes run, trace the value of i • The trace statement will run over and over again until the loop condition, i < 20, is no longer true

  9. In loop statement, we can change the index to run any number of times by changing the value in the condition

  10. Generate Instances of a Class using a loop • Using code loop to drag instance of a class into the movie at the run time (Flash: Generating_Instances) • Steps to drag: • Right-click on the movie-clip in window library • Choose linkage properties • Select Export for ActionScript • To export the class at run time in order to communicate with it via AS • Change the class name to the current movie-clip to call the object out of library panel

  11. var _boarder:mcBoarder; for (var i:Number = 0; i < 6; i++) { _boarder = new mcBoarder(); addChild(_boarder); }

  12. Placing Instances Created by a Loop var _boarder:mcBoarder; var _boarderX:Number = 132; var _boarderY:Number = 267; var _boarderR:Number = 0; for (var i:Number = 0; i < 6; i++) { _boarder = new mcBoarder(); addChild(_boarder); _boarder.x = _boarderX; _boarder.y = _boarderY; _boarder.rotation = _boarderR; _boarderX += 75; _boarderY -= 75; _boarderR -= 45; }