user1995781
user1995781

Reputation: 19463

Flex detect element in container

How can I detect if there is any element in a container?

Example code:

<s:VGroup id="myGroup"></s:VGroup>

if(myGroup.getElementAt(0)){
    //Got element inside
}else{
    //Nothing inside
}

When I tried to run the above code, I get this error

RangeError: Index 0 is out of range.

How can I detect if there is any element loaded into the VGroup?

Thank you.

Upvotes: 0

Views: 39

Answers (1)

JeffryHouser
JeffryHouser

Reputation: 39408

Use the numChildren property.

if(myGroup.numChildren > 0){
    //Got element inside
}else{
    //Nothing inside
}

Upvotes: 1

Related Questions