tags:

views:

310

answers:

4

I want to check whether string is empty or not

when i create object=Shared.getLocal("abc");

it assigns undefinded to the object at the first time

 if(object.data.name=="undefnied") {
         // is this correct   
 }
A: 

I am not sure with flex, but it should be undefined or null without quotes, I think.

S.Mark
+1  A: 

undefined is a value, not a string to compare to. You want:

if (object.data.name == undefined) {
    //This property on your SharedObject was/is not defined.
}

Note that setting a property on a SharedObject to null does not delete it, it must be deleted with "delete".

Tegeril
+1  A: 

Use the hasOwnProperty function to test if the variable exists. For example:

    if ( object.data.hasOwnProperty("name") ){
        // Ok. object.data.name exists...
        var value_of_name : String = String(object.data["name"]);

        // Check for non-null, non-empty
        if ( value_of_name ){
             // Ok. It is a non-null, non-empty string
             // ...
        }
     }
Michael Aaron Safyan
A: 

To answer your exact question (if is empty), I'd do this:

var name : String = object.data.name;
if(name != null && name.length > 0) {
    //also, a common actionScript technique is to say if(name && name.length...)
    //same difference.
}
jeremym