I want a Boolean to have one one of three properties; true, false, or default.
Otherwise I need code like this in the getter/setter:
//WHAT I'M USING
private var _useTimestamp:Boolean;
private var _useTimestampDefault:Boolean;
public function get useTimestamp():Boolean
{
if (_useTimeStampDefault)
{ return GlobalSettings.useTimestamp; }
else
{ return _useTimestamp; }
}
public function set useTimestamp(value:Boolean)
{
_useTimestampDefault = false;
_useTimestamp = value;
}
public function get useTimestampDefault():Boolean
{
return _useTimestampDefault;
}
public function set useTimestampDefault(value:Boolean)
{
_useTimestampDefault = value;
}
This is what I want to do instead:
//What I want, A LOT less code
private var _useTimestamp:Boolean;
public function get useTimestamp():Boolean
{
if (_useTimestamp == default)
{ return GlobalSettings.useTimestamp; }
else
{ return _useTimestamp; }
}
public function set useTimestamp(value:Boolean)
{
//Timestamp can be set to "true, false, or default/null"
_useTimestamp = value;
}
Also, I want to use this feature as default values in properties
public function traceMe(str:String, useTimestamp:Boolean = GlobalSettings.useTimestamp)
{ ... }
But that throws the following error:
1047: Parameter initializer unknown or is not a compile-time constant.
I could create a new class that has one single property which handles boolean values, but that means that it is treated as an instance, and not as a real value, which means that statements like this might be off:
if (customBool) { … }
Is this possible? If I set the boolean to null, it will default to false, and that is not what I want.