For Loops
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: For Loops

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2

    For Loops

    Hello! Recently, I have been trying to create a for loop. I understand how basic for loops work, but seem to be stuck on this one; most tutorials cover duplicating movie clips, but I'm interested in seeing how it would be written for a different statement. Here is the code that I want to be made into a for loop:
    Code:
    onEnterFrame = function() {
    		boxV1._x++;
    		boxV2._x++;
    		boxV3._x++;
    		boxV4._x++;
    }
    The above code currently works for what I am doing and the four movie clips do move across the stage, but I would like to write it as a for loop. Here is the current for loop that I am using:
    Code:
    onEnterFrame = function() {
    	for (i=0;i<101;i++){
    		"boxV"+i._x++;
    	}
    }
    As you can see, I'm quite confused on the statement of the for loop. I feel like I am close, but have written it wrong somehow. Also, it doesn't matter at this point how many are specified to move (I only need four, but in the loop I specified 100). Any help would be appreciated!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    883
    Hi,

    This will help you,
    PHP Code:
    onEnterFrame = function ()
    {
        for (
    04i++)
        {
            
    _root["boxV" i]._x++;
        }
    }; 
    yours also made it go to 101, not 100. The first obejct of the loop would be zero.( 0 = 1, 1 = 2, 2 = 3)

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thank you Fruitbeard! That worked perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com