View Full Version : scripted loops
newbieMX
March 15th, 2003, 12:00 AM
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[i] = eval (*m*+i);
mc[i]._alpha = 75;
mc[i]._yscale = 80;
mc[i]._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!
lostinbeta
March 15th, 2003, 12:12 AM
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..
for (i=0; i<=5; ++i) {
mc = eval ("m"+i);
mc._alpha = 75;
mc._yscale = 80;
mc._xscale = 80
}
senocular
March 15th, 2003, 12:18 AM
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 "
lostinbeta
March 15th, 2003, 12:19 AM
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?
lostinbeta
March 15th, 2003, 12:20 AM
Nevermind, I think I get it now.
'DOH!!!!!
:hangover:
newbieMX
March 15th, 2003, 12:24 AM
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 :-\
senocular
March 15th, 2003, 12:26 AM
please keep your questions about this topic in this thread ;)
newbieMX
March 15th, 2003, 12:28 AM
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)
senocular
March 15th, 2003, 12:31 AM
happens all the time :)
are there certain parts about the script you dont know or is it all just a blur?
newbieMX
March 15th, 2003, 12:36 AM
basically its all just a blur.. the book its sorta complicated, but any explanation from any part of the code will do =)
Scootman
March 15th, 2003, 12:37 AM
mc = newArray();
for (i=0; i<=5; ++i) {
mc[i] = eval (*m*+i);
mc[i]._alpha = 75;
mc[i]._yscale = 80;
mc[i]._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
newbieMX
March 15th, 2003, 12:44 AM
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.. :)
newbieMX
March 15th, 2003, 01:21 AM
Can somebody please help me out here?:-\
Scootman
March 16th, 2003, 08:59 PM
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..
newbieMX
March 16th, 2003, 11:51 PM
:-\ 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:
Scootman
March 17th, 2003, 07:15 PM
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.
newbieMX
March 17th, 2003, 07:34 PM
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 :)
Scootman
March 17th, 2003, 07:50 PM
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
newbieMX
March 17th, 2003, 09:12 PM
Oh man, thx alot!;) 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 =)
Scootman
March 17th, 2003, 11:54 PM
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
jimw00d
March 19th, 2003, 05:36 PM
can I ask an additional question:
how can I use a button to control the movement of the ball in the downloadable loop.fla?
It would be good if I could use a button to start the movement which would then be stopped by an upper limit in a loop for example
newbieMX
March 19th, 2003, 08:01 PM
Hey scoot, with a brief explanation from you and my little knowledge of actionscripting, I made this stupid little sig ^_-. I have one more question about loops, this is the code that i used
onClipEvent(EnterFrame) {
for(i=0; i<20; ++i; ){
scale=Math.random()*100;
this.x_scale=scale;
this.y_scale=scale;
this._alpha=Math.random()*100;
this._x=Math.random()*100;
this._y=Math.random()*400;
}
}
Now if you were to try this code, they would be a bunch of square or whatever object you're duplicating all around the place with different _alpha . Now how would I make it so that it wouldnt be so quick at changin? Is there some way to change the speed so the duplicated object appears more slowly? For instance I made a tweened animation and I just want it duplicated and in different places of the movie, how would I do it so it does the whole tweened movie is seened? If you can help plz do ;)
lostinbeta
March 19th, 2003, 09:26 PM
jimw00d: I have no clue what you mean, check my attachment, is that anywhere close? You should start a new thread with this problem. If you already did, then please don't crosspost, but since you did already, can you post a link to that thread?
newbieMX: I don't wanna rain on your parade or anything, but your footer is way too big. The footer requirements can be found here.....
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=16926
lostinbeta
March 19th, 2003, 09:29 PM
Oops, the attachment MIGHT help ;)
jimw00d
March 20th, 2003, 04:31 AM
Lost.
I was thinking more along these lines..
Fla attached.
But I can't figure out how to return the red block to its original position when the loop has finished.
thanks for helping on this one though, no one else seemed remotely interested
lostinbeta
March 20th, 2003, 10:53 AM
Like this?
jimw00d
March 20th, 2003, 11:36 AM
well almost but I only want the block to return when the button is pressed for a second time.
Can I make a button do two different things depending on whether it has or hasn't been pressed before.
If I have two buttons:
One button-enter site
Second-read text
1 User presses enter site button- block slides in from left as in file, maybe one colour
2 Or user presses read Text button-block slides in with a different colour (I can handle this with a setRGB thing)
3 Then having read text, user decides to enter site and presses enter button, at this point I want the same box to slide in with the same colour as step 1
I guess we are close, well you more than me.
Have I explained myself?
lostinbeta
March 20th, 2003, 11:49 AM
Alright, how about this then.
Scootman
March 20th, 2003, 10:48 PM
newbieMX...
onClipEvent(EnterFrame) {
for(i=0; i<20; ++i; ){
scale=Math.random()*100;
this.x_scale=scale;
this.y_scale=scale;
this._alpha=Math.random()*100;
this._x=Math.random()*100;
this._y=Math.random()*400;
}
}
this is your code and you want it to run slow enough for people to see... well for one... if you are doing a frame loop... you shouldnt have a for loop inside it. the for loop will do everything in one frame... making it all done at once. if you want it to happen one frame at a time take the for loop out... and i noticed an error in your code
this.x_scale=scale;
this.y_scale=scale;
should be
this._xscale = scale;
this._yscale = scale;
(underscore goes before xscale and yscale)
if you want it to go even slower than 1 time every frame... you can 1) slow down the frame rate or 2) do it with a variable and only do the frames with a factor of a certain number
to do that you would have to use the modulous operator (the percent sign) say you do 10 % 2... it will divide 10 by 2 and then return the remainder. if 2 goes in evenly then it returns 0. you can use this to check if you go into a frame say every 2 times...
example for your code:
onClipEvent(load){
counter = 0;
}
onClipEvent(EnterFrame) {
counter ++;
if(counter % 2 == 0)
{
scale=Math.random()*100;
this._xscale=scale;
this._yscale=scale;
this._alpha=Math.random()*100;
this._x=Math.random()*100;
this._y=Math.random()*400;
}
}
hope this helps
newbieMX
March 21st, 2003, 12:58 PM
Once again scoot you have been of great help ;) ! I will experiment with the code further. Thx alot man:beam:
lostinbeta
March 21st, 2003, 03:59 PM
Originally posted by lostinbeta
newbieMX: I don't wanna rain on your parade or anything, but your footer is way too big. The footer requirements can be found here.....
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=16926
newbieMX
March 21st, 2003, 09:42 PM
Yes I know sorry, I will take it away soon just working on a new one :hangover:
UNFLUX
March 21st, 2003, 10:34 PM
well it just froze me up a couple times just to get into this
thread. I recommend you taking it down sooner please, cuz I'm
sure I'm not the only one.
thanks. :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.