When you cast any object to a boolean value you get true if the object is not null and false otherwise, I like to change this behaviour for some objects. I want that some objects return false even when they aren’t null
I know that in ActionScript 3.0 we can change some default behaviours of an object using Proxy. Can we do the same for Boolean(object) or object as Boolean? And how this can be done?
I want to ask this after the next thought:
I have this code:
if (someObject)
someObject.DoSomething();
That’s mean that DoSomething is only called if someObject is not null but that is only because the “real” code behind that is this:
if (Boolean(someObject) == true)
someObject.DoSomething();
And works because any object is automatically casted to Boolean and the result is true, but if the reference points to null the result is false.
I want to know if I can change THAT behaviour without adding a new function like isTrue(someObject) or something like that.
Thanks in advance, and sorry for my poor English.
No, CustomClass(object) and
asare cast operators, behavior of both is defined by language. And Boolean(object) is, afaik, global function with language-defined behavior (and there is no function overloading.) There is no class-level operator for type-casting in ActionScript 3.0, you have to implement some property for true/false checks.