Learn about utilizing the looping structure command in this Flash Professional 8 advanced training video series.


More DIY videos at 5min.com

Video Transcription

Now, this is not very much of a game right now because we only got one bubble on the screen. So, as our last little effort, we are going to want to set this up so that we will actually got a few bubbles for user to chase and we can make a game out of it. Let us close up our preview window and see about setting that up. Now, let me get those drag limits while I am thinking about them. In our start drag, I had set up a top and a right limit. But remember, ,different objects are going to behave differently because of their relative registrations points. We are measuring our limits from the drag point, not necessarily the registration point. So it can be a little bit confusing and you may want to play around with it for each object that you are setting up in this way. I will just set them both to zero and we will just see if that works a little bit better. Now, in dealing with making multiple bubbles, we are simply going to make a change so that when you press the start game button, instead of getting a single bubble, you are going to get multiple bubbles. Now, we can sort to do this in a kind of cloggy sort of way by just calling the function a couple of different times. I could do it. If I test my movie with that, every time I press the game button, I am going to get two bubbles. That is not too bad but that is a little bit cloggy and it is not really very sophisticated or extensible if we want to make changes to our action script later. So, let us add in a new structure and I do not think we have used this in our lessons yet but this is a looping structure. It allows you to basically repeat a statement as many times as you would like to. It is going to have a similar syntax to what we used before but a few differences. Let us just go ahead and try it out. Now, I am going to put a line above our make a bubble statement so we got a room for it. And the structure we are going to look for is generally referred to as a “for loop.” That is because it starts out with the word “for.” Now, I will hit the parenthesis here because then we will get some tool tips and you can see there are structures, kind of liking conditional statement. We are going to specify some perimeters that will allow us to loop through a set of code a number of times. We will use grouping braces to specify the code that we are going to loop and we need to set up a few perimeters here to get the loop going. The first one is an initial condition. Now, generally, I am basically making a counting variable if you want to think of it that way. And the most common counting variable that is conventionally used is the letter I. you can pretty much use any variable that you would like to hear. But you will see a lot of people making “for statements” with and I counting variable. Now, if we wanted to be truly correct, we could instantiate this variable like we did before using bar keyword and we also want to set its initial condition. I am going to start counting it zero. So, I am going to set I equal to zero for my first condition. Now, I can see in the tool tip that it is using semicolon to separate this. So, I am going to type semicolon. We will go on to our next element. The condition is when we are going to stop the looping behavior. Now, in our first loop, let us set this up so that it repeats the procedure ten times. That would mean that I would be checking to see if the I variable had reached ten or not, or basically if it was less than ten. Now, the next perimeter allows me to pump this variable up or increment it. Generally, you would do this by one but you could also count by twos or fives or whatever you wanted to. In our case, I want to increment it by one. Remember, our short hand operator for bumping up a variable by one would be plus, plus. Now, we will finish our looping context out by adding our group embraces, up at one at the end of my four statements to start things out. I am going to want to repeat this statement over and over again. And basically it would be like putting the make a bubble function call ten times in a row down here. And I will close