0

I'm sorry if I'm being vague in any way as I'm nooby at AS3.0 and stackoverflow. I simply wanna push the i variable to add to the variable _bullets.

var i:int = 0; //initializing the i variable

_bullets.push(i);

//Loops thought all the bullets on stage
for (var i:int = 0; i > _bullets.length; i++)
{
//Some code...
}

The result i wanna achieve is that the for-loop now has something to loop through. If more information is needed I will do my best to provide it.

  • Can you please clarify your question? What does `_bullet` contain, and what do you want to do in the loop? Do you want to fill the `_bullet` array in the loop to initialize it, ou is there already something in it that you want to use in the loop? – Benoît Guédas Feb 13 '13 at 19:24

1 Answers1

0

I don't really understand what your are trying to do, but there are at least two mistakes in your code:

  1. the variable i is declared two times: at the fist line, and in the loop.
  2. the continuation test in the loop is wrong. It should be

    for (var i:int = 0; i < _bullets.length; i++)
    

_bullets is supposed to be an Array of int ? So _bullets.push(i) will add the content of the variable i (here 0) at the end of your array. Is it what you wanted to do ?

Then, if you want to iterate through the elements of _bullets, you can use a for each loop if you don't care about the value of i:

for each (var bullet:int in _bullets ) 
{
    // some code using bullet
}

it is equivalent to

for (var i:int = 0; i < _bullets.length; i++ ) 
{
    var bullet:int = _bullet[i];
    // some code using bullet
}
Benoît Guédas
  • 801
  • 7
  • 25