Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Messaging w/ Complex Data Types

Avatar

Level 1
Hey everyone,



I'm having issues trying to pass complex data type objects I
created using the BlazeDS messaging service.



To be more exact, I have an AC3 class "Cargo" that I wrote
that contains only five public properties of type 'String':
contents, length, width, height, and weight. The application I
wrote allows the user to enter these properties using text input
components, and then publishes the Cargo object through the
Producer.send() function.



Below is the pertinent code:



private function sendMessage():void {

var message:AsyncMessage = new AsyncMessage();

messageObj.contents = ti_contents.text; //messageObj is of
type 'Cargo'

messageObj.length = ti_length.text; //ti stands for
TextInput, as I am grabbing the user's input.

messageObj.width = ti_width.text;

messageObj.height = ti_height.text;

messageObj.weight = ti_weight.text;

message.body = messageObj;

producer.send( message );

}



private function messageHandler( event:MessageEvent ):void {

messageObj = Cargo( event.message.body ); //TYPE COERCION
ERROR HERE!!!!

}





The sending and receiving work fine, I'm having no issues
getting the messaging service to work. However, when I cast the
'event.message.body' as type 'Cargo' I get a type coercion error.



I cannot find help with this anywhere as all the examples use
Strings or other primitive types.



Any suggestions on how to get this to work?
2 Replies

Avatar

Not applicable


I have never done it like that, but using Blaze-DS and remove
objects you can try this?



private function messageHandler( event:MessageEvent ):void {

Cargo = vent.message.body as Cargo;

}





Ries



Avatar

Level 1
thanks for the reply reis, but because there is a type
coercion error between the event.message.body of type Object and my
messageObj of type Cargo, if I try the "as" operator it just
returns null.



Any other ideas?