2 X "For" Loops With XML
Hi there,
I got a issue trying to run 2 "for" statements within the one xml onLoad statement. I can't see why it doesnt work, though it works fine when there is only one "for" statement. Here's my code:
myXML.onLoad = function(ok) { if (ok) { allData = this.firstChild.childNodes; for (i=0; i<allData.length; i++) { newBut = _root.attachMovie('contentTemp', 'content'+i, i); newBut._y = -50; newBut._x = (i*30)+30; } allOtherData = this.childNodes[15].firstChild; for (k=0; k<allOtherData.length; k++) { newBut = _root.attachMovie('otherTemp', 'other'+k, k); newBut._y = -50; newBut._x = (k*20)+20; } } else { trace('error'); } }; myXML.load('myText.xml');
Are you simply not allowed to run two "for" statements at once? Any ideas?
KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 02-19-2006, 06:54 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Looping Loops Of Loops
First of all, a BIG hello to the Flash kit Community...
this is my first post to this board, wont be my last :P
now to business... i have a small problem. What i need to create is an accelerating counter... eg.
Code:
at frame | the counter says| special counter
1 0 25
25 1 24
49 2 23
72 3 22
94 4 21
so as the movie iterates through the special counter drops by 1 until the counter is looping at 25fps. the counter(ascending)controls a movieclip which contains images of numbers(these refer to seconds). when that counter gets to 10 it resets and pushes the "tens of seconds counter" up by one......now what i want to do id
i hope i havent lost anyone....
now when the "seconds" start iterating at 25fps i want the "tens of seconds" to begin accelerating .... and so on through minutes, tens of minutes and finally hours.
so far it is shaping up as an evil series of nested ifs.... there has to be a better way.... any ideas?
tricky bits arise also as "tens of minutes" and "tens of seconds" loops from 1 to 6 ....
"hours" shouldnt need to iterate for too long anyways...
if anyone has some ideas i would very much like to hear them :P
I'm Having Problems With "if " Loops Inside "for" Loops. Help?
I am trying to execute an "if" statement inside a "for" loop. There are no formating errors in the script, but when I test the movie, it hangs for a minute or so, then a message comes up saying that my code might be to complex. Could somebody maybe shed some light on this?
Do While Loops
I must be retarded....
I want a loop something till count = 19. but my script keeps scrashing me or returns only when count = 19.
do {
count = count + 1;
trace (count);
} while (count eq 19);
i want this result in my trace...
1
2
3
4
5
6
7
8
9
.
.
.
19
######FOR Loops#####
hi guys, a little problem with my for loop
when i want to set up a counter limited to lets say 30 iterations using the FOR loop, Flash counts all the way to 30 without executing the code inside the FOR loop.
Code:
on (press) {
for (c=1;c<target;c++){
duplicateMovieClip (crap, "crap"+c, c);
_root["crap"+c]._x = c*50;
c = c+1;
target=30;
}
}
any one know what i'm talking about? please help!
Loops?
Going to the basics. How do you make a loop. Could you please post the script that shows an example.
I would like to Loop a script to add a variable everytime making it +1 everytime Then starting over after say 100.
Thanks in advance.
Andy
Two Loops At Once?
i have seen 2 loops or what looks like 2 loops happening at once and out of sequence. After the first loop has ended the second loop continues while the first loop restarts. I dont understand how that is possible? If it is possible or an explaination can be given, please reply how.
Thanx
Mp3 Loops
im trying to download a loop as an mp3, and whenever the download screen comes up, the loops is played in real player instead of saved on my hard drive. is there a way to make the loop save to my drive from real player? or how can i disable real player from automatically launching?
thanks
dazvoltron
ps is the flash player easier to use and smaller than mp3's? if so could someone tell me where i could find a tutorial for flashplayers? thanks alot
Loops?
I'm trying to get a movie clip to dulpilcate 20 times. It will only duplicate twice. Heres my code tell me what im doing wrong
on (press) {
for (j = 0; j < 20; j++) {
duplicateMovieClip("bug","bug",1);
bug._x = random(100);
bug._y = random(20);
}
}
Thanks
Davy
Loops
Here is a small script I wrote that is working fine for me, but I'm not sure why it works the way that it does. My movie is playing at 24 fps and I am using this frame with an MC on the main timeline as a simple timer to sit on the frame until the loop is satisfied...then moving on to the _root frame label "rest". My thougth was that the loop would be incrementing "i" 24 times per/sec, which isn't the case at all. The numers I have now (1000*75) is about 2.5 seconds. Why is this????
onClipEvent (enterFrame) {
for (i=0; i<(1000*75); i+=1) {
}
if (i>=(1000*75)) {
_root.gotoAndStop ("rest");
}
}
Loops
hello all,
is it possible to set up a loop to for example do this
tellTarget (_level1) {
gotoAndPlay ("menu1");
}
for 1 to 10 ? (ie level2,menu2)
Thanks for any help
Al
Loops...
Not sure if this belongs in the Newbs forum, but since it does involve FLASH 5 actionscript....anyway.
I never used any actionscript in FLASH 4 except for basic preloaders and the geturl, and i have only a VERY basic knowledge of C++, (which this looks alot like), so im stuck on this stupid thing alot of you probably think is easy as hell:
How do i tell my movie when to stop a loop. I figured out how to get a loop going (and was i proud? You bet) by saying
if (_currentframe = 9) {
gotoAndPlay (1);
}
Now what im trying to do is get it to STOP looping so i can play the rest of my movie. I was hoping maybe there was a way to do so when a certain amount of seconds, or maybe rotations of the loop, have elapsed but damned if i know how.
Also, for those of you who know C++, is there a way to simply declare and use a variable? Like if i want to declare a variable called numLoops, and increment it by 1 every time currentframe = 9, then using it later in an if statement like if(numLoops = X) [code for stopping loop].
Probably can, but again, no ideas how.
Thx for any help
-Fate
Loops
cant belive this slipped my mind
how do you make a sound loop?
Mp3 Loops
hello friends,
hope you are having a splendid day, afternoon, evening, night where ever you are right now. here my questions. I working with a bunch of loops that are randomly playing, all of that works fine, the problem is just that when I replay the sound onSoundComplete a little splitsecond there is silence, so it ain't really looping. Is it recommended to use the sound object at all when wanting to play background music?
If not, cause I have been working on this one as well, I created seperate swfs with my loops in them, same concept they randomly picked then playd. But then my neat fade in fade out function I wrote is no good, cause it seems the get and setVolume are again reserved for the sound object.
So basically two questions, and answer to one of them will make me happy enough.
1. Anyway to avoid skipping when using the sound object for looping backgroundmusic
or
2. Can I set the volume of a loaded movie the same way I can with a loaded Sound?
Loops?
How can i define how many loops for a symbol to travel along a path?
I tried to make a flash with 2 object -
1) a planet (circle)
2) a planet Ring (a hollow circle)
how do i make it that the the planet is in the center of the planet ring? Because when i tried it with the planet layer on top of the planet ring layer the planet covers the ring layer and the ring appears to be behind it.
eh about the planet question. It is like bringing the planet back of the ring at certain part of the loop so that the ring will look like it is looping around the planet
Loops ?
does anyone know any easy to understand tutorials on loops (for loop, while, do while loop and all the rest of that) for some reason i can not grasp it, its really annoying me.
thanks
najib
Loops
I have a movie clip containing 4 frames. I would like the frames to loop a limited number of times before stopping. How can I do this using actionscript ?
Loops
I am trying to get a loop to work but every time it runs through the loop and then the code giving me only one duplicate of the movie post99. here is the code:
for (i=2;i<100;i++)
{duplicateMovieClip("post1", "post"+i, 1);
setProperty("post"+i, _x, i+50);
setProperty("post"+i, _y, i+50);
setProperty("post"+i, _visible, "true");}
any help would be appreciated. Thanks
Loops
hey guys...i have a problem with looping movie clips. i have this one movie clip inside another one, so that when you click a button, it plays the "inside" (i guess you could call it child) movie clip...but the problem is this: you click the button and it plays the movie fine...but it plays it over and over and over again....it loops it. is there a way to turn loops off in movie clips?? thanks for all your help in advance!!
While Loops
Can someone help and give a tut opn while loops? When used, etc...
Loops
Hey all-
I am working on a book by Macromedia on Actionscripting and I am stuck on loops. Is there a website that explains them a bit better and gives examples one would use for real life situations?
I am talkin about stuff like:
var i=-1
while(++i < something){
name = "item" + i;
this[name].removeMovieClip();
}
}
Loops
hey guys....loops loops loops....why aren't they synchronized!!!!!???
always empty space between the same loop.....plaese help
Help With Loops
ok i'm very confused about how loops work... so could someone break apart what these lines of script are doing and translate it into english so i can understand and recreate it.
for (var i=1, i<=2; ++1) {
*some stuff*
}
also what is "this" in actionscript
hwap462@hotmail.com
Loops
Hi!
I have made a short presentation in flash and need help. i want it to play through till it reaches frame 106 and then play on continuous loop from frame 100 to 106. how do i do this? is there an actions code i type, if so what?
thanks alot,
andy
For Loops...
I'm trying to get 2 loops to concatenate in parallel and can't do it!
to make it clearer here is my code:
conc = new Array(50, 10, -10, -50, -90);
for (j=7; j<40; j=j+7) {
for(h=0; h<5; h++){
_root["balls"+j]._x = conc[h];
....
i'm guessing that since the h loop is nested in the j loop, during every looping session for 1 element or the j loop all the elements in the h loop are activated.
i need them to loop in parallel so for each 1j there is an 1h at every looping session instead of for each 1j there are 5h.
i tried so many ways, i'm giving up soon. i'm sure it's right under my nose. but i already see double....
anybody???
thnx
For Loops?
I'm trying to build a mult-user environment, using a password system for sign in. I want to put a for loop on the sign in button, so that it will check all the usernames and passwords without me having to manually input them into my .swf. So, I'm wondering, how would I do this?
Loops
Hi All,
Could someone please tell me if there is a way to loop back to a previous line in AS?
I know about loops "while" "for" and "for_in", but they don't seem to fit the bill for what I want.
Failing this is there some way to say something must not be equal to something else, such as "value 1 must not equal "bob" ?
Thanks.
Do ... While Loops
Hey, how do you make it so that a Do...While Loop runs the loop every 1 second? LIke it will run once, then run again 1 second later, then again 1 second later...etc.
While Loops
I would like to use conditional statements to move a button in the main timeline up, over and back down. I need to be able to watch while it moves.
Based on the condition, it is also possible that I may need the button to move down, over and back up. This is also the reason that I can't just create a movie clip without AS.
While Loops?
OK...am just trying this SIMPLE bit of code form a book I have:
FLASH MX ActionScript for Designers. (great book mind you)
but for some reason..I can see no reason why this wont work:
I have a movie clip (just a tween of an arrow "easing" up..thats it)
with this code ON the clip:
Code:
onClipEvent (load) {
this._alpha = Math.random()*100;
this._x = Math.random()*550;
this._y = Math.random()*400;
}
On the root time line I have the frame action of:
Code:
k=0
i=Math.random()*20;
while (k<i) {
duplicateMovieClip("arrow_clip", "arrow_clip"+k, k)
}
All I keep getting is code in the script..etc..etc..errors ...and it never works.
Im just trying to play with the duplicate MovieClip a certain amount of times....on the stage..with some random placement and alpha......
Also..can I put an unload "this" on the last frame n the tween? So the movie will always keep 20 clips on the stage at a time..but NEW ones (so alpha and location change all the time)
This seems simple to do..what am I overlooking?
thanks
-whispers-
For Loops Using I
Hi Guys,
I have 20 buttons that I want to define actions for. Instead of defining 20 separate call back functions, I wanted to do this in a FOR loop since all of the buttons share the same action. My buttons are named "btn1_mc" through "btn20_mc". So, I created this for loop:
------BEGIN
for (i=1; i<20; i++) {
buttons_mc.btn[i+_mc].onRollOver = function() {
myColor = new Color(this);
myColor.setRGB(0xFFFF00);
_root.name_txt.text = this.btn+[i+_txt].text;
};
buttons_mc.btn[i+_mc].onRollOut = function() {
myColor.setRGB(0xFFFFFF);
_root.name_txt.text = "";
};
}
------END
But this doesn't work. I traced "i" and it is incremeting properly, but for some reason my buttons aren't responding...any idea what I'm doing wrong?? Do i need to store the button names in an array first?
Thanks,
Josiah
Loops
what is correct syntax
_root["firework"+i+"banger]="yes";
for
firework1banger="yes"
the syntax above is wrong
Thanks
Loops
When you find a loop you like there's a button that says 'add to my fk' and I clicked it and it took me to my "favorites house" page but it didnt add the loop. What do I do?
Loops :S
Ok, so i have a function that moves an MC across the stage upon a button press. I would like the button to tell a different MC to play its last 10 frames, and THEN call the function that moves the first MC across the stage.
I can get the button to do this simultaneously, but this is undesirable. How can i make it so that the function is called AFTER the second MC has finished its last 10 frames?
Ive tried various loops but to no avail, as my coding skills are somewhat limited.
Thanks in advance
Do While Loops
Hey, I am trying to have a movie clip shoot where the mouse position is when they click a button, heres my script, I havent done any action script in a long time so I can't really see whats wrong.
code: on (release) {
shootx = _xmouse;
shooty = _ymouse;
CowboyMC.play();
duplicateMovieClip(bullet,bullet01,1);
bullet01._x = CowboyMC._x;
bullet01._y = CowboyMC._y;
do {
bullet01._x = bullet01._x - 5;
bullet01._y = bullet01._y + shooty * 0.2;
} while(bullet01._x < shootx && bullet01._y < shooty)
}
Loops
Ok, I've already searched the forums in trying to figure out how to do loops. I also looked on the internet. Everywhere it says a simple animation should loop unless there's a stop. Well, I've been trying that and am really getting frustrated. All I have is a circle in frame 1 on the left of the screen, with a keyframe. Then on like frame 30 the circle is on the right. The motion tween has it the circle move across the screen but IT WON'T LOOP. I didn't specify any ActionScript and I can't find any on any of the frames. I have also tried putting a GotoAndPlay(1) at the last frame but nothing will work. It just goes through the motion tween once and that's it-- done. I've even read the 'tutorial' offered on this site, which doesn't seem to work (or I'm incompetent) in that it says to make the circle a movie clip and then change it back right away, which didn't really accomplish anything. Please help! Thanks in advance.
Loops
i've created something very simple:
a 10x10 rectangle box moving across the screen from left to right - in 10 frames using a tween.
however i want this to keep on happening throughout the site.
i know i should use some kind of loop - what sort of actionscript would i need - repeat loop?
or is there a tool in flash to do it for you?
(To save me from copying and pasting the frames ad infinitum...)
Thanks
Loops Within Loops...
Hello all... simple question...
Can I have an if loop within an if loop?
So
if (x==y){
if (a==b){
do this
}else{
do this
}
}else if (x==z){
do something else
}
Basically I have a series of if statements checking what a user types, I want to then check if a movie is loaded on level 1, if it is, unload it, if its not, write out a message saying there is no movie on that level.
Ta
Loops
i was trying to make a countdown loop.
It counts down and when it gets to a certain number it moves to the next frame. How do i do this with the actions only on the one frame?
For Loops
Alright, I'm somewhat new to AS and have been learning everything i know from these tutorials, so please bear with me when i ask my idiotic question
can someone please break down for loops for me? what they're doing, how to use them, etc? I searched the flash help pages and tried searching the tutorials here (the search engine here considers "for" to be a useless word and doesn't include it in its searches) but i couldn't find anything better than "for (init; condition; next){}".
Thanks,
Convinced He Needs Something Besides If-Thens
[HELP] Loops - Other Then For Loops
Hello everyone,
I just have a quick question. Is it possible to use a loop OTHER then the for loop?
This is what I want to accomplish. I have a dynamic text box, and a button. When you hold down the button the dynamic text box increases by 1 (number starting at 1940)
I want it to keep going until you release the button and thought to do so with a loop
If someone could please tell me how to go about doing this, it would be greatly appreciated
Thanks
For Loops
Can I make a for loop wait for an animation, such as the rolling of dice?
Cap On Nr Of Loops
Ive got a problem with a big loop (about 6000 loops). It works, but eventually I get a system-alertwindow saying:
"A script in the movie is causing the flashplayer to run slowly. If you continue, the computer may be unresponsive. Do you want to abort the script?"
Well, this is a good securitymeasure for infinite loops, I guess, but in my case its ever so annoying.
Isnt there a way to circumvent this alertwindow, for instance by informing the flashplayer somehow that "a ****load of memory is going to be used in the following loop, so dont go *****ing about it", or something like that?
Loops..
Hi,
I'm trying to unload all movie clips from continuing to spawn and move if I change to a certain frame. I've stopped them from spawning with a simple boolean statement but I'm having trouble with the unloading of movie clips that were already spawned just before changing frame in the scene.
I can do it, with really awful coding like so:
Code:
_root.ArrowSpawn = 0;
UnloadMovie("leftarrows1");
UnloadMovie("leftarrows2");
UnloadMovie("leftarrows3");
UnloadMovie("leftarrows4");
UnloadMovie("leftarrows5");
UnloadMovie("leftarrows6");
UnloadMovie("leftarrows7");
UnloadMovie("leftarrows8");
UnloadMovie("leftarrows9");
UnloadMovie("leftarrows10");
UnloadMovie("uparrows1");
UnloadMovie("uparrows2");
UnloadMovie("uparrows3");
UnloadMovie("uparrows4");
UnloadMovie("uparrows5");
UnloadMovie("uparrows6");
UnloadMovie("uparrows7");
UnloadMovie("uparrows8");
UnloadMovie("uparrows9");
UnloadMovie("uparrows10");
Etc...
However obviously it would be better to do the same thing with a loop. I tried using a foo loop method and didnt manage to get it working. Can anyone help?
Thanks I need foo pity.
[F8] Loops
I have three lines of code that assign the same style sheet to three different text fields, each named sequentially:
text_bullet0_mc.bullet0_txt.styleSheet = my_styleSheet;
text_bullet1_mc.bullet1_txt.styleSheet = my_styleSheet;
text_bullet2_mc.bullet2_txt.styleSheet = my_styleSheet;
Is there anyway to run the above block through a loop, so that a single line of code could be executed three times, each time incrementing the numbers up by 1. I’m thinking it could be accomplished with something to the effect of:
for (var i:Number = 0; i < 3; i++) {
"text_bullet" + i + "_mc.bullet" + i + "_txt".styleSheet = my_styleSheet;
}
Of course, when I execute the “for” loop above, I get errors because my synatax is off. Can anyone help me format it correctly?
Thanks in advance.
TheLegioneer
Flash 8, ActionScript 2.0
[F8] Help With For Loops
I know there is a much better way to program this using a for loop but cant seem to get it to work properly. Each movieClip when attached needs to be unloaded when the next is attached. This code does work (except nothing is unloaded yet) but is very inefficient. Please include brief thought process with code so I can better understand it. Thanks
//Web Functions
btnWeb.onRollOver = function(){
globe._alpha = 80;
}
btnWeb.onRollOut = function(){
globe._alpha = 40;
}
btnWeb.onRelease = function(){
display.vc.attachMovie("webAnimation", "webAnimation2", depth++)
display.gotoAndPlay(2);
}
//Video Functions
btnVideo.onRollOver = function(){
film._alpha = 80;
}
btnVideo.onRollOut = function(){
film._alpha = 40;
}
btnVideo.onRelease = function(){
display.vc.attachMovie("videoAnimation", "videoAnimation2", depth++)
display.gotoAndPlay(2);
}
//Graphic design functions
btnGraphic.onRollOver = function(){
pencil._alpha = 80;
}
btnGraphic.onRollOut = function(){
pencil._alpha = 40;
}
btnGraphic.onRelease = function(){
display.vc.attachMovie("graphicAnimation", "graphicAnimation2", depth++)
display.gotoAndPlay(2);
}
//animation functions
btnAnimation.onRollOver = function(){
guy._alpha = 80;
}
btnAnimation.onRollOut = function(){
guy._alpha = 40;
}
btnAnimation.onRelease = function(){
display.vc.attachMovie("aniAnimation", "aniAnimation2", depth++)
display.gotoAndPlay(2);
}
//client functions
btnClients.onRollOver = function(){
head._alpha = 80;
}
btnClients.onRollOut = function(){
head._alpha = 40;
}
btnClients.onRelease = function(){
display.vc.attachMovie("clientsAnimation", "clientsAnimation2", depth++)
display.gotoAndPlay(2);
}
//company functions
btnCompany.onRollOver = function(){
logo._alpha = 80;
}
btnCompany.onRollOut = function(){
logo._alpha = 40;
}
btnCompany.onRelease = function(){
display.vc.attachMovie("companyAnimation", "companyAnimation2", depth++)
display.gotoAndPlay(2);
}
//contact functions
btnContact.onRollOver = function(){
phone._alpha = 80;
}
btnContact.onRollOut = function(){
phone._alpha = 40;
}
btnContact.onRelease = function(){
display.vc.attachMovie("contactAnimation", "contactAnimation2", depth++)
display.gotoAndPlay(2);
}
For Loops?
Im more than stumped when it comes this assignment in my class. Can anybody point me in the right direction?
Write a for loop which populates an array with random numbers. The array should have 42 elements, and the numbers can be in the range of 1-100, integers only.
Loops ?
Hey,
I was just wondering if anyone knows how I could make a certain number of frames loop for a specific number of times before moving on to the following frames. For instance, how could I make frames 1-5 loop 10 times and then move onto frame 6 etc.? It seems like it should be pretty simple, but I'm not sure how do to it.
Thanks!
While Loops
Hi Everyone. I havent done flash for a while and im having a bit of difficulty with the coding...im trying to get a button on the main movie to jump back and fourth frames in an embeded movie. Basically in psuedo code I wanna say:
(this is an example of when the inner movie is on frame 3 and I want to get it to frame 1)
On mouse over
do while
inner movie is not on frame 1
then
current frame - 1
loop
then break the loop when its on frame 1....
I'd apprecaite any help its annoying the hell out of me as I havent done flash in a while,
Cheers
Loops
I'm trying to create a loop on a frame that will pause the frame for 5 to 10 seconds using the loop while()..end loop in flash 4. Any suggestions on how to do this? Thanks, cm .
|