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=null):void{
   if (obj != null){
    if (obj.hasOwnProperty("i_test"))
     i_test = obj.i_test;
    if (obj.hasOwnProperty("o_test"))
     o_test = obj.o_test;
    if (obj.hasOwnProperty("s_test"))
     s_test = obj.s_test;
   }
  }
 }

Later,
Mark
 
On 10/23/06, mdoberenz <[EMAIL PROTECTED]com> wrote:


I'm pretty sure this is possible, but I can't get it to work.

I'm wanting to typecast a generic object that gets returned by a
WebService call into a VO, but I'm having some issues.
Say I have a VO of the following:

public class TestVO{
[Bindable] public var i_test:int;
[Bindable] public var s_test:String;
[Bindable] public var o_test:Object;
}

Then I get an object back from a WebService call that has a similar
structure, can't I just do the following?:

var typeCastTry:TestVO = RETURN_OBJ as TestVO;

When I do this, typeCastTry gets set to null.

Any help would be awesome!

Mark


__._,_.___

--
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
Software development tool Software development Software development services
Home design software Software development company

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

__,_._,___

Reply via email to