Skip to main content
kas8
Known Participant
March 30, 2011
Answered

for loop going mad

  • March 30, 2011
  • 1 reply
  • 645 views

Ive got this for loop, but for some weird reason it malfunctions:

-when triggered, it runs infinite times.

-it only triggers when segmenten1 or segmenten3 are 0, which is weird, because it should also work when segmenten0 and 2 and 4 are 0...

here is the for loop:

stage.addEventListener(Event.ENTER_FRAME,addmetaal);
function addmetaal (evt:Event) {
    for(var animteller=0;animteller<5;animteller++){
        if (this["segmenten"+animteller]==0) {
            trace("segmenten"+animteller)
            for(var teller6=0; teller6<4; teller6++) {
                var enzym_mc:EnzymAnim1=new EnzymAnim1();
                var metaal_mc:MetaalAnim1=new MetaalAnim1();
                Vijanden.push(enzym_mc);
                Vijanden.push(metaal_mc);
                metaal_mc.rotation=enzym_mc.rotation=Math.random()*360;
                metaal_mc.x=enzym_mc.x=xco[animteller];
                metaal_mc.y=enzym_mc.y=yco[animteller];
                addChildAt(enzym_mc,numChildren-90);
                addChildAt(metaal_mc,numChildren-90);
            }
        }
    }
}

do you know why this is malfunctioning?

it seems to me like that when any of the segmenten variables hits 0, it should trigger 2nd for loop, and repeat that 4 times.

the xco and yco are arrays which store values for the x and y coordinates for spwaning the addchilds, this works fine.

the segmenten variables are declared as following:

var segmenten1:Number=17, segmenten2:Number=17, segmenten3:Number=17, segmenten4:Number=17, segmenten0:Number=17;

please help me out here

This topic has been closed for replies.
Correct answer kglad

those for-loops are in an enterframe loop so, the outer loop should repeatedly execute.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 30, 2011

those for-loops are in an enterframe loop so, the outer loop should repeatedly execute.

kas8
kas8Author
Known Participant
March 30, 2011

what do you mean?

i want this loop to check if any of the segmenten variables hit 0, and if so, it must execute

or is there a better way to do that?

kglad
Community Expert
Community Expert
March 31, 2011

i don't know what you're doing but you complained your for-loop keeps executing and i pointed out that's what you should expect.

what is about your code that you don't expect?