A class has a method to update its instance properties from a given Object.
For some reason looping through properties of this fails in ActionScript 3.
I tried something like:
class myThing() {
public var A:String;
public var B:String;
public var C:String;
...
public function bindToObject( obj:Object){
for( var s in this){
if( obj.hasOwnProperty(s)) this[s] = obj[s];
}
}
}
This way the loop never executes, as if this had no properties at all.
Please advise on a smart way of copying Object properties to an instance of my class.
You might want to try doing it the other way around. Meaning, parsing the source object’s properties, and assigning its values to the target object. I looked into this matter myself and here is how I implemented that method:
It’s very similar in intent to your bindToObject method, except the fact that the method parses the parameter object. The reason for choosing this way, was that in my context, all the properties of the target object, were considered optional (i.e. if I pass only one property for the source object, out of 3, for instance, then it wouldn’t make sense to parse all of the target object’s properties). The context might be different in your case, however.