This content has been marked as final. Show 3 replies
AFAIK you can only down cast (to a base class)
What you're trying to do in this example is not legal. "o" is an instance of Object, not an instance of Test. You can't arbitrarily cast an object to any class you want--the object must actually be an instance of the class (or a subclass).
However, you mention webservice calls, so I'm assuming you're trying to get the webservice to return an instance of your custom class. AFAIK, this can't be done with the WebService tag--you must use RemoteObject in conjunction with FDS or ColdFusion as your server. In that case, you specify a mapping of your custom ActionScript class to a Java class on the server using the RemoteClass metadata tag. Here's some more info:
Otherwise, you cannot cast any object returned by a WebService call to a custom class. They're just plain Objects and you have to know the contents.
Thanks to the both of you.
It had already started to dawn on me in the meantime (there's nothing better for getting a grip on a problem than stepping away from the pc for a while:-) ). Coming from the Java world I should've known that you can never cast an object to something it doesn't extend.
Inlineblue : You're right : I was trying to mimick the behavious of Flex Dataservices and remote Java objects but this time with a webservices interface (server side code is J2EE). It's much easier if the data in Flex is encapsulated in objects.
Right now I'm thinking about creating a utility class that will 'copy' back and forth the data in the objects returned from webservices over to my custom classes in Flex/Actionscript. I don't know if it'll gain me anything in the long run but I just hate working with non-typed data.
Thanks anyway !