There is no standard way of doing this however you could tackle it in 2 different ways.
Version 1: Constructor method
public class Person {
public function Person(raw:Object=null) {
if (raw != null) {
for ( var key:String in raw ) {
try {
this[key] = raw[key];
} catch (e:Error) {}
}
...
This is kind of error prone. If a property named key does not exist assignment will fail and if the type doesn't match or can't be coerced automatically it will fail as well.
Version 2: flash.utils.describeType()
Much more sophisticated, gives you more control. First you have to create an instance of Person and call describeType().
var o:Object = { ... } // raw person data
var p:Person = new Person();
var typeDesc:XML = flash.utils.describeType( p );
for (var key:String in o) {
var node:XML = typeDesc.variable.(@name==key)[0];
if ( node != null ) {
// Person class has a property *key*
p[key] = o[key];
}
}
But watch out when using getters and setters instead of public variables. You can't access them with typeDesc.variable, instead you have to use typeDesc.accessor and check if its access attribute is not writeonly.
Regarding your type key. To load a class dynamically you can do:
var clazz:Class = flash.utils.getDefinitionByName(raw.type+"");
var person:Person = Person( new clazz() );
Of course raw.type may contain Person or com.package.Person as long as your target class exists and is being compiled with the project or dynamically loaded with SWC.
Take a look at:
http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getDefinitionByName()
and http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#describeType()
Hope this helps :)