As3 verifaricare se una variabile è empty


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static function empty(variable:*) : Boolean {
  2.  
  3. var isEmpty:Boolean;
  4.  
  5. if (variable == null || variable == undefined) {
  6. isEmpty = true;
  7. }
  8. else if (variable is String) {
  9. var str:String = variable.replace(/^\s+|\s+$/g, '');
  10. isEmpty = (str.replace(/\s+/g, ' ') == "" || variable == "" || variable == "0" || variable == "false");
  11. }
  12. else if (variable is Number || variable is int || variable is uint) {
  13. isEmpty = (variable == 0);
  14. }
  15. else if (variable is Array) {
  16. isEmpty = (variable.length == 0);
  17. }
  18. else if (variable is Boolean) {
  19. isEmpty = (variable == false);
  20. }
  21.  
  22. return isEmpty;
  23.  
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.