|
Note you could do this generically for any type...
as a quick hack, you could loop through the anonymous object provided in
the constructor and set the property on the class iff it had such a property...
something like:
for (var prop:String in obj)
{
if
(hasOwnProperty(prop))
this[prop] =
obj[prop];
} ...though you'd have to watch out for read only
properties.
For a more robust (but complex) solution you
could use flash.utils.describeType to get an XML description of your class and use E4X statements to
find and ignore read only properties. Internally we often have to do this in FDS
so we use the Flex utility class
mx.utils.ObjectUtil.
var classInfo:Object =
mx.utils.ObjectUtil.getClassInfo(this, null,
[includeReadOnly:false]);
You could then check that the property name was defined in
the classInfo.properties structure. Pete
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Mark Doberenz Sent: Monday, October 23, 2006 1:37 PM To: [email protected] Subject: Re: [flexcoders] Typecast a generic Object into a VO
I figured it out. I just made the VO have a constructor that set the
values if you wanted to convert it to a VO:
public class TestVO
{ [Bindable] public var i_test:int; [Bindable] public var o_test:Object; [Bindable] public var s_test:String; public function TestVO(obj:Object= if (obj != null){ if (obj.hasOwnProperty i_test = obj.i_test; if (obj.hasOwnProperty o_test = obj.o_test; if (obj.hasOwnProperty s_test = obj.s_test; } } } Later, Mark
On 10/23/06, mdoberenz <[EMAIL PROTECTED]
-- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required) Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe __,_._,___ |

