# AS3 - If there is more than X amount of an instance

In an as3 document I am creating it so that every frame comes 5 more hearts at random positions on the stage. I want it to display a textbox, with an instance name of "firstText" if there are more than x amount of heartRandom instances on the stage.

Here is my code:

addEventListener(Event.ENTER_FRAME, loop); function loop(event){ var h1:Number = Math.random() * 550; var h2:Number = Math.random() * 400; var h3:Number = Math.random() * 550; var h4:Number = Math.random() * 400; var h5:Number = Math.random() * 550; var h6:Number = Math.random() * 400; var h7:Number = Math.random() * 550; var h8:Number = Math.random() * 400; var h9:Number = Math.random() * 550; var h10:Number = Math.random() * 400; var hF1:heartRandom = new heartRandom(); var hF2:heartRandom = new heartRandom(); var hF3:heartRandom = new heartRandom(); var hF4:heartRandom = new heartRandom(); var hF5:heartRandom = new heartRandom(); addChild(hF1); addChild(hF2); addChild(hF3); addChild(hF4); addChild(hF5); hF1.x = h1; hF1.y = h2; hF2.x = h3; hF2.y = h4; hF3.x = h5; hF3.y = h6; hF4.x = h7; hF4.y = h8; hF5.x = h9; hF5.y = h10; }

## Answers

Define maximum value for number of hearts, in the example - 200

var maxHearts: uint = 200; var currentHeartCount: uint; function loop(e: Event){ //Your code with hearts generation //You are generating 5 hearts every frame currentHeartCount += 5; if(currentHeartCount >= maxHearts){ //Display your firstText TextField //or create it here, if you don't have it already firstText.visible = true; //Stop loop? removeEventListener(Event.ENTER_FRAME, loop); } }