I am converting a project from AS3 to OpenFL. One problem I found is that I often use the OR operator to decide what to return from a function. I have looked around, but could not find an answer.
In haxe the || operator is for booleans and even with operator overloading you can’t change the return type.
So I guess you’ll have to do that in a slightly different way.
public function getComponentByID(id:String, shallowSearch:Bool = false):Component{
var component = null;
if ((component = getHotspotByID(id, shallowSearch)) != null) return component;
if ((component = getButtonByID(id, shallowSearch)) != null) return component;
if ((component = getCableByID(id, shallowSearch)) != null) return component;
if ((component = getSocketByID(id, shallowSearch)) != null) return component;
if ((component = getLightByID(id, shallowSearch)) != null) return component;
return component;
}
public function getComponentByID(id:String, shallowSearch:Bool = false):Component{
var component = null;
for (i in 0...5) {
component = switch (i) {
case 0: getHotspotByID(id, shallowSearch);
case 1: getButtonByID(id, shallowSearch);
case 2: getCableByID(id, shallowSearch);
case 3: getSocketByID(id, shallowSearch);
default: getLightByID(id, shallowSearch);
}
if (component != null) break;
}
return component;
}