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);
    }
}

Need Your Help

EXC_BAD_ACCESS with getter

ios objective-c exc-bad-access

Having a problem with the following code (using xcode 5 with ios 7.1)

how do I loop through file names in stata

stata

1) Is it possible to create a vector of strings in stata? 2) If yes, is it then possible to loop through the elements in this vector, performing commands on each element?