arrays - multiple instances of the same object spaced out using a loop is only creating one -


i had hard time trying word question properly, i'm sorry if seems confusing. i'm using flixel library in flash builder. may not important butcause knows little more me or little as3 see i'm doing wrong.

anyway, i'm trying create 10 instances of square object made. have pass x y coordinate place , works. ive tested if do:

var testsquare:bgsq; testsquare = new bgsq(0,0); add(testsquare); 

it works fine , adds square @ 0,0 told to, want add 10 of them move next 1 that's created 25 px right (because each square 25px)

my problem ever see 1 square, it's making 1 instance of still.

anyone possibly have idea doing wrong?

var counter:int = 0; var bgsqa:array = new array;  (var ibgs:int = 0; ibgs < 10; ibgs++)     {     bgsqa[counter] = new bgsq(0,0);     bgsqa[counter].x += 25;     add(bgsqa[counter]);     counter++;     } 

there's lot you're doing wrong here.

first off, you're using pseudo-iterator (counter) access array elements through loop instead of, well, using iterator (ibgs).

second, don't see in array (bgsqa) you're iterating through. it's no wonder you're having problems. here's should do.

var bgsqa:array = []; for(var i:int=0;i<10;i++) {     var bgsq:bgsq = new bgsq(i * 25, 0);     add(bgsq);     bgsqa.push(bgsq); } 

that should if post accurate.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -