Flash AS3: How to check if an XML object actually has contents

Okay guys,

Many of you might have known this, but if you were me, there would be times when you actually forget how to do this properly (or I’m getting senile lol). Anyway, that’s why I decided to make a post about this so I myself can refer to it in times of need.

Consider you have an AS3 XML object like this: <root><Element1></Element1></root>

For some reason, you don’t know if <Element1> has any child element, or even text content, or not. And here’s how you’re gonna find it out:

trace(myXML.Element1.children().length());

If it outputs “0”, you’re 100% certain this is a completely empty XML element!

And that’s it! Hope this helps 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s