Simple for loop

I’m trying to make a simple for loop that makes a line move. But it won’t work, and when i search for “for loop” it gives me all these dynamic things that are WAY over my head. Here’s my code on a line:

 onClipEvent(enterFrame){
	for(i = 0; i <= 77; i++){
		amount = i;
		line1._x = (-77 + amount);
	}
}

The way i see it, the i should increase by 1 each time the loop is run, and then the line will move up by 1 until it is at x = 0 (it starts at x = -77). But when i preview it in flash and html, nothing happens at all.

Sorry for all the newbie questions lately.

Thanks,
NWC :trout:

loops happen all in the same frame. At the end of the enterframe the loop has completed i is at 77 and _x is at 0. Flash refreshes the screen line is at 0. Next frame the loop goes through again, all at once. gets back to 77, _x set at 0, Flash refreshes the screen line is at 0. Its an repeating process that goes on and on but does nothing because the loop is happening all at once.

if you want the line to move then you would use something like


onClipEvent(enterFrame){
         if (i < 77)
                  i++
                  amount = i;
                  line1._x = (-77 + amount);
         }
}

then i only goes up 1 every frame and movement can then be seen.

Thanks a bunch sen. In other languages, I usually use for loops, but I guess they’re different in flash from what i’m used to.

Ok, question #2, I know you guys just love me :).

onClipEvent(enterFrame){
	if((_root.lines == 2) && (this._yscale < 21)){
		lines12._alpha = 100;
		lines12._yscale ++;
		_root.counter++;
	}
}
onClipEvent(enterFrame){
	if(i <= 77){
		i++;
		this._x -= 1;
		if(i == 77){
			_root.lines = 2;
		}
	}
}

The 2nd line (bottom AS) works correctly, it moves to where i want it to, then stops. But the first line (top AS) doesn’t do anything.

Why doesn’t this work?

was the _yscale set to anything before this script? because as you may or may not know, the scales (_xscale, _yscale) are actually well, the scales of the object for each axis. they are initially 100, full scale. how i have a strange feeling this isn’t your problem, so can you explain exactly what you’re trying to do?

I’ve got 2 lines coming in from the side. Then when they get to their stopping point I want a line where each of them stops to grow vertically. then when these 2 lines stop, i want lines to go in from the 2 line’s 4 endpoints to have a box around my name :). I’ll send the .fla of what I have so far. I think the logic is right, it’s just something like an enterFrame instead of load, but i’ve tested everything I can possibly think of, and nothing works :(.

nali, i hate to say this, but you may be better off drawing the box yourself. but if you really want to do this through actionscript, let me know and i’ll code it for you (with comments of course ;)).

heh, i want the cool lines drawing the box. And I thought you had to do that in actionscript. You don’t need to write the program for me. Just tell me what’s wrong with my syntax in my actionscript so far. Or write the program, whatever’s easier for you :). Thanks a bunch thor.