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
Post a Comment