[flexcoders] Question about using [RemoteClass(alias=...)]

2010-09-06 Thread John Mesheimer
I have an ActionScript class that creates a custom Review object, like so:

/ Review.as
/ Taken from one of Adobe's online samples
package samples.restaurant
{
import mx.formatters.DateFormatter;

// [RemoteClass(alias=samples.restaurant.Review)]
[Bindable]
public class Review
{
public function Review(source:Object=null)
{
// some date formatting stuff happens here
}

public var restaurantId:int;
public var restaurantName:String;
public var restaurant:Object;
public var reviewDate:Date;
public var reviewer:String;
public var rating:Number;
public var title:String;
public var reviewText:String;
public var email:String;

}

}

This class lets me take an ArrayCollection of generic Objects from the
server, loop through it with something like new Review(source[i]) and get
a bunch of Review objects in an ArrayCollection. Works perfectly.

I also need to be able to write a Review object (a Java object) to the
server, so I add [RemoteClass(alias=samples.restaurant.Review)] above
the ActionScript class declaration. This way I can declare a public var
review:Review, call an addReview(review) on my RemoteObject service, and
my server receives a Review Java object. This works perfectly too.

The problem is that once I add this [RemoteClass(alias=...)] line, doing
new Review(source[i]) no longer works as expected. Given the same
ArrayCollection of generic Objects as before, new Review(source[i]) will
still create a Review object, but now all its properties are null.

If I comment out the [RemoteClass(alias=...)] line I can properly cast
generic objects to Review objects again (but then I am no longer able to
send a Review Java object to the server).

Is this the way it's supposed to work? (I hope I've stated my problem
clearly.) How can I accomplish both tasks using a single Review.as class?

Thanks for any help, folks.

John

PS. I am using the Flex 3.5 SDK.


[flexcoders] Re: Question about using [RemoteClass(alias=...)]

2010-09-06 Thread John Mesheimer
Forgive me, I be a dingbat...

By setting the [RemoteClass(alias=...)] line, the thing I got back from
the server was not an ArrayCollection of generic Objects, but of strongly
typed Review (AS) objects, which didn't need any casting.

All solved now. Nothing to see here...


On Mon, Sep 6, 2010 at 1:52 PM, John Mesheimer john.meshei...@gmail.comwrote:

 I have an ActionScript class that creates a custom Review object, like so:

 / Review.as
 / Taken from one of Adobe's online samples
 package samples.restaurant
 {
 import mx.formatters.DateFormatter;

 // [RemoteClass(alias=samples.restaurant.Review)]
 [Bindable]
 public class Review
 {
 public function Review(source:Object=null)
 {
 // some date formatting stuff happens here
 }

 public var restaurantId:int;
 public var restaurantName:String;
 public var restaurant:Object;
 public var reviewDate:Date;
 public var reviewer:String;
 public var rating:Number;
 public var title:String;
 public var reviewText:String;
 public var email:String;

 }

 }

 This class lets me take an ArrayCollection of generic Objects from the
 server, loop through it with something like new Review(source[i]) and get
 a bunch of Review objects in an ArrayCollection. Works perfectly.

 I also need to be able to write a Review object (a Java object) to the
 server, so I add [RemoteClass(alias=samples.restaurant.Review)] above
 the ActionScript class declaration. This way I can declare a public var
 review:Review, call an addReview(review) on my RemoteObject service, and
 my server receives a Review Java object. This works perfectly too.

 The problem is that once I add this [RemoteClass(alias=...)] line,
 doing new Review(source[i]) no longer works as expected. Given the same
 ArrayCollection of generic Objects as before, new Review(source[i]) will
 still create a Review object, but now all its properties are null.

 If I comment out the [RemoteClass(alias=...)] line I can properly cast
 generic objects to Review objects again (but then I am no longer able to
 send a Review Java object to the server).

 Is this the way it's supposed to work? (I hope I've stated my problem
 clearly.) How can I accomplish both tasks using a single Review.as class?

 Thanks for any help, folks.

 John

 PS. I am using the Flex 3.5 SDK.