actionscript 3 - Action Script 3. How to add multiple children of 1 instance? -


i'm creating flash game. need make player lives - heart images. if player have 5 lives should added 5 hearts <3 <3 <3 <3 <3. have image instance name heart. how add them correctly?

i've tried this:

var lives:number = 4; var currenthp = lives; var heart:heart = new heart(); var hparr:array = new array(); function hp() {              (var i=0; i<lives; i++) {         heart = new heart();         hparr[i] = heart;         hparr.push(heart);         heart.x += heart.width+20;         addchild(heart);     }     trace("array length" + hparr.length); } 

this correctly return 5 trace("array length" + hparr.length);, means hearts added array. problem 1 heart added. can problem?

change for loop this:

    (var i=0; i<lives; i++) {         heart = new heart();         hparr.push(heart);         heart.x = ( heart.width + 20 ) * i; // here trick!         addchild(heart);     } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -