E4X: Test If Attribute Exists

Quick Tip:

When using E4X (AS3) to test whether an attribute exists, if you write:

?View Code ACTIONSCRIPT
var nX:Number = (shape@nY) ? shape@nY : 0;

an exception will be thrown. You should instead write:

?View Code ACTIONSCRIPT
var nX:Number = (shape.attribute('nY').toString()) ? shape@nY : 0;

I had hoped that Flash/Flex/AS3 had an hasAttribute method, but I guess this will do.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks