Loop Lesson

In this lesson, Jerry discusses the use of loops in lessons 8a, b, and c, as shown in the Notes to those lessons.

Many of the methods used to animate various objects are simple functions repeated over and over. In these basic frame by frame animation examples, we have used the same statements over and over in order to produce an entire movie. This works, but it would not be practical for a 100 or 1000 frame movie you may eventually create.

So, we go back to the php manual and study loops a bit more. Then, we can take the repeating statements and boil them down to one single loop statement, producing the same results as before, with a smaller file size.

A) Use the same code as the other lesson 8 examples, up to and including the point where we add our shape to the movie

$myShape1=new SWFShape();
$myMovie=new SWFMovie();

B) Now, we define our loop, beginning with a starting number, then a condition setting how long to loop, then the amount to increase our loop each time. Remember the opening bracket to start your loop code section.

for($i=0; $i<12; $i++){

C) Next, we include the code to be repeated until the loop condition is met, 12 times in this example. Notice that I included all the motions covered in the combined lesson 8s to demonstrate how looping makes it easier to create complex motions.


D) Don't forget to close the loop code section with a closing bracket.


E) Then we save and output our movie with the object tags as usual

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" ID=objects WIDTH=460 HEIGHT=80>
<PARAM NAME=movie VALUE="lesson8d.swf">
<EMBED src="lesson8d.swf" WIDTH=460 HEIGHT=80 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">

Next lesson, we will learn to change the color and transparency of our movies contents!

Code summary for lesson 8d: