Posted By

BoNzO on 11/11/09


Tagged

empty as3


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

forze
tspitzr


As3 verifaricare se una variabile è empty


 / Published in: ActionScript 3
 

  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  

You need to login to post a comment.