I´m trying to fire an event from my App with the following approach:
this.fireEvent({type: "myEvent", source: this, data: {x:1, y:2, id:3 }});
My Expectations were that the "data" with x,y, id is transfered to the server. But in the network protocol I only see this.
<cmsg xmlns="http://www.nextapp.com/products/echo/svrmsg/clientmessage.3.0" i="7">
<dir xmlns="" proc="CSync">
<e t="myEvent" i="C.3"></e>
</dir>
</cmsg>
The Event reaches the client as expected - but there is no data.
What I´m doing wrong ?
Does a simple string as data
Does a simple string as data work?
Yep
this.fireEvent({type: "MyEvent", source: this, data: "MyData"});
ends up in:
<cmsg xmlns="http://www.nextapp.com/products/echo/svrmsg/clientmessage.3.0" i="1">
<dir xmlns="" proc="CSync">
<e t="MyEvent" i="C.3">MyData</e>
</dir>
</cmsg>
- looks good
this.fireEvent({type: "unityReady", source: this, data: {xyz:"MyData"}});
is empty again....
I believe the client js
I believe the client js implementation process only string data. You may have to encode your JSON structure as a string (maybe just wrap in double quotes) and see if that gets around it. You can also try declaring input properties and xml serialisers for these properties in your implementation. I have found simple hacks easier to work with :-)
i will give the JSON
i will give the JSON approach a try.
works fine
Works fine.
For the client side I took a JSON serializer from here:
http://www.sitepoint.com/javascript-json-serialization/
So my fireEvent method looks similar like this:
this.fireEvent({type: "myEvent", source: this, data: toJSON({xyz:"MyData"})});
On Server side I implemented a SerialPropertyPeer - very straight forward
public class Unity3dPeer implements SerialPropertyPeer{
@Override
public Object toProperty(Context paramContext, Class paramClass, Element paramElement) throws SerialException {
String json = paramElement.getTextContent();
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.alias("MyModel", MyModel .class);
MyModel u3dem = (MyModel )xstream.fromXML(json);
return u3dem;
}
@Override
public void toXml(Context paramContext, Class paramClass, Element paramElement, Object paramObject) throws SerialException {}
}
thanks for the help