PDA

View Full Version : AS3: Do I need to cast null?


pm771
07-30-2008, 04:41 AM
I started learning FLEX 3 using 'From the Source' book and have Action Script question.

If I have a function that normally returns a custom object but in some cases needs to return null, do I need to cast null as the object?

Something along these lines:

function Sample():SomeObject {
var myObj:SomeObject
....
if (someCondition) {
myObj = new SomeObject();
} else {
myObj = null; // Or should it be: null as SomeObject ?
}
return myObj
}

TIA, Eugene

senocular
07-30-2008, 05:14 AM
nope. null is a valid value for object types. In fact when as fails, it returns null.

Flash Gordon
07-30-2008, 05:31 AM
in other words, the object declaration is set to null.
var myObject:Object; is null.

pm771
07-30-2008, 03:45 PM
Thank you for your prompt response.

null is a valid value for object types.

What would be a good source (on-line or otherwise) for this type of information?

senocular
07-30-2008, 04:06 PM
It's all explained in the docs.
http://livedocs.adobe.com/flash/9.0/main/00000043.html