Scripted loops

Hey, I’m new to the forums and Flahs itself. Well, I’ve always have been interested in Flash, just never got into it as much as now and I must say I really enjoy it alot. I recently got a book and got to the chapters which covers loops. I first explained the motion tween loops, thats ofcourse is self explanatory, the it covered the scripted loops. Here is where i got messed up. They show an example it looks something like this :

mc = newArray();
for (i=0; i<=5; ++i) {
mc* = eval (m+i);
mc*._alpha = 75;
mc*._yscale = 80;
mc*._xscale = 80
}

I really don’t understand the concept of it and what it does… if anyone would be so kind to explain it to me. It would be greatly appreciated. OK thx!

If you ask me, that makes no friggin sense.

Why would you change the alpha and scale of an array?

I think I am overlooking something, but I am lost.

It would make sense if it said something like…

[AS]for (i=0; i<=5; ++i) {
mc = eval (“m”+i);
mc._alpha = 75;
mc._yscale = 80;
mc._xscale = 80
}[/AS]

its just adding each of those clips in the array for future reference. In that script alone, theres no advantage, but it would supposedly lead to easier management of the clips further down the road :-\

One thing to be aware of though, newbieMX, is how lostinbeta corrected the eval statement replacing * with "

But why does it change the _xscale and _yscale and such as well Sen? I don’t get it.

But I am also very tired right now (more than usual), any explanation though?

Nevermind, I think I get it now.

'DOH!!!

:hangover:

Well, the code doesn’t matter, the book was just giving me an example of what the “for” code looked like. That’s what i need explained to me… I need to know how the for loop works… if you can help , please help :-\

please keep your questions about this topic in this thread :wink:

yes, sorry about that, by mistake i guess i clicked on post new thread, sorry…:blush: (please someone explain to me how the for loop works thx, if u could give me a script example to see how it works would be greatly appreciated)

happens all the time :slight_smile:

are there certain parts about the script you dont know or is it all just a blur?

basically its all just a blur… the book its sorta complicated, but any explanation from any part of the code will do =)

mc = newArray();
for (i=0; i<=5; ++i) {
mc* = eval (m+i);
mc*._alpha = 75;
mc*._yscale = 80;
mc*._xscale = 80
}

this is just for the for loops, not the arrays in case you needed that too… so heres for loops

the syntax is basically

for(initialize variable, set upper limit, count by what)
{
code…
}

for(i=0; i <= 5; i++)

it starts your variable i, while its less than or equal to 5 it will keep going, and each time it runs through a loop it will increment by 1.

for(i=0; i <= 5; i += 2)

this wouuld do the same thing except it would increment i by 2
this would only go three times though… (0, 2, 4, 6) when it gets to 6 it will have met the exit condition (i <= 5) because its not less than five, and its not equal to it, so it stops looping.

hope this helps

yes, it helps tremendously.thx alot man. Now one more question regrading loops… how would it look like if you were looping a movie clip? and is it possible, and what would happen if it does, for example, what would looping a movie clip be good for? I ask this because I have heard you can do this with mc’s… :slight_smile:

Can somebody please help me out here?:-\

looping with mc’s is just a loop that happens every time it enters a frame. you do this by selecting your mc, going to actions and putting your code within the header:

onClipEvent(enterFrame)
{
code…
}

this will make the code happen each time it runs a frame

onClipEvent(load)

this can be used to initialize variables… it runs it only once, when the clip is loaded on the stage

hope this helps…

:-\ I’m not sure if I’m just not good with flsh Scoot, but I kinda get it and don’t at the same time. I only have a week with Flash and learning alot from the book. Hmm… if i can ask you for a favor… is it possible to show me an example of using the loop with a movieClip? If so thx alot !:beam:

here is a small example, there is much more you can do with it though… this fla is just scripted movement… in the load part it initializes the speed, and in the loop it move the mc across the stage.

Thx man! But that wasen’t the sorta loop I was referig too… I was refering to a scripted loop. I want to know how the (for) loop works with a movie clip. But thanx man I really appreciate the help :slight_smile:

oh i didnt realize what you were talking about at first… heres a different one…

the code is all in the first frame… it just loops and duplicates a movie clip five times… i commented it…

hope it helps

Oh man, thx alot!:wink: Now I do get it, plus you included the duplicateMovieClip in it, so makes it double the thx! I’ll study your code further I saw you included random y, x! So I will experiment with it and make some kind of animation. Well thx alot man, you really helped =)

if you get stuck on anything another good place to look if you have it is the actionscript library… it tells you parameters for functions and stuff and is pretty helpful sometimes… just go to the help menu and then actionscript dictionary… then just look up what you need… glad i helped