Hi, I want to pass optional parameters to a new instance of class via an object.
I can read the parameters but i don’t know how to assign them to the new instance.
In as3, i did that :
all the optionnals are in params and i allows me to add new properties in object and to be free to pass the parameters in any order.
function Forme(cible:DisplayObjectContainer, x:Number, y:Number, largeur:Number, hauteur:Number, params:Object = null) {
if (params) {
for (var property:*in params) {
if (hasOwnProperty(String(property))) {
this[property] = params[property];
} else {
trace("Attention, la propriété " + property + " n'est pas disponible pour l'objet :" + this);
}
}
}
}
In haxe, idon’t know what to put instead of ??? (above)
private function new(cible : DisplayObjectContainer, x : Float, y : Float, largeur : Float, hauteur : Float, ?params : Dynamic = null){
if (params != null) {
for (property in Reflect.fields(params)){
if ( Reflect.field(params, property)!=null) {
??? = Reflect.field(params, property);
}
else {
trace("Attention, la propriété " + property + " n'est pas disponible pour l'objet :" + this);
}
}
}
}
thanks for your help