voodoochild
voodoochild

Reputation: 25

Using numChildren values of multiple movieclips and adding them together to obtain a sum variable?

I have 15 empty(with blank keyframe) movieclips in the scene and i call png files into them.(by load(new URLRequest)) I want them to work like slots. With correspondent add PNG buttons on the scene, each slot will have a PNG. There are "substract PNG button"s on the scene

When all the slots are full, I want to show user a message (like warning_mc.visible=true)that "All 15 slots are full, please make at least one of the slots empty".

For this what i thought is to detect all the movieclips numChildren values and sum them up and with a variable that will take the sum value, if the variable value exceeds the sum, the warning message will be shown to user.

But i think numChildren values cannot be used in that way? Any other solution for this?

Upvotes: 0

Views: 1747

Answers (1)

BadFeelingAboutThis
BadFeelingAboutThis

Reputation: 14406

You want a model similar to this:

var mySlots:Vector = new Vector<MovieClip>(mc1,mc2,mc3, mc4, mc15); //make an array/vector of all your containers

function get slotTotal():int {
    var count:int = 0;
    for(var i:int=0;i<mySlots.length;i++){ //go through each slot and see if it has children
        if(mySlots[i].numChildren > 0){
            count++;
        }    
    }
    return count;
}

function get isValid():Boolean {
   return (mySlots.length - slotTotal == 1); //if total slots is one less than all the containers, then return true
}

Upvotes: 1

Related Questions