Nope, an instance must actually be of a particular type in order to coerce it to that type.
 
Try adding metadata to your class:
 
[RemoteClass(alias="TestVO")]
public class TestVO
{
}
 
The MXML compiler will generate the correct code to register an alias for the TestVO class as "TestVO" and thus create actual instances of TestVO on deserializing a response.
 
Also note that the as operator does not throw an exception if the instance is not of the correct type - instead it will just return null. If you want an exception you need to use casting syntax:
 
var typeCastTry:TestVO = TestVO(RETURN_OBJ);
 
Pete


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of mdoberenz
Sent: Monday, October 23, 2006 10:41 AM
To: [email protected]
Subject: [flexcoders] Typecast a generic Object into a VO


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