I don't believe it's possible.

However, if your objects "match", then perform a for .. in loop... you don't
need to copy them individually.

Eg.


Person.as

package

{

[Bindable]

public class Person

{

public function Person()

{

}

 public var personName:String;

public var personAddress:String;

}

}



Test.as


var objectInstance:Object = new Object();

objectInstance.personName = 'Joe';

objectInstance.personAddress = '555 Joe St.';

 newPerson = new Person();

 for(var i:String in objectInstance)

{

newPerson[i] = objectInstance[i];

}


HTH,

Brendan


On Sat, May 8, 2010 at 8:18 PM, anagnost68 <[email protected]> wrote:

>
>
> I have a class defined called Person that has a name and address. If I have
> an Object with a name property and address property.
>
> var object:Object = new Object();
>
> object.name = "name";
> object.address = "address";
>
> I'd like to be able to do this:
>
> Person person = object as Person;
>
> But, it generates an error. Is there a way to convert the Object into a
> Person object without individually copying each property?
>
> Thanks
>
>  
>



-- 
Brendan Meutzner
http://www.meutzner.com/blog/
http://www.riajobs.com

Reply via email to