if-statements – checking strings for being null
hello again!
Yesterday I wrote some code again and had to check if a String is null or not. The check was performed in a for-loop.
Below is some example code:
-
[… some more code here …]
-
private function foo():void
-
{
-
var i:uint;
-
for( i = 0; i < 10; ++i)
-
{
-
if(!arrToFill[i])
-
{
-
arrToFill[i] = '';
-
}
-
}
-
}
This function was called different times and I wondered, that the if-statement returned false everytime.
For me it was theoretically correct that an Array-Element with a value of ” is not empty, because ” is an empty String for me, but it is something.
ActionScript3 doesn’t work like that, so for AS3 a String with a value of ” is equal to null or 0.
Conclusion:
If you have code like this and want to preallocate an element, just set it to 1. Then you can do a simpy
if(!arrToFill[i])
and everything would be fine.























