Mapping objects

"Luke DeWitt" <[email protected]> Tue, 4 Jul 2006 15:16:30 -0300
Newsgroups gmane.comp.java.openamf.user
Organization PenguinFire Media
Message-ID <00be01c69f95$fb6ebd80$7a16a8c0@pflukedev>
Hey Guys,

I finally got OpenAMF up and working (had to use the last release though) and I am am so sorry to ask this question again, but I have read through a bunch of the mail list archives and I am getting nowhere!

I used this tutorial here: http://www.flash-db.com/Tutorials/helloOpenamf/hello2.php?page=4 to get started in the wonderful world that is java to flash remoting. This was a simple little tutorial, but I am looking to do more than just echo a String. At this moment I am trying to send a custom java object (SmackletType) to Flash. I figure that if I can get this working I will have no problem doing the next couple of steps which are just extenstions of this.

Here is some code to help people visualize what I am doing:

Java Code for Smacklet Type:

package com.flashdb.domain;

import java.io.Serializable;

public class SmackletType implements Serializable {      // does this need to be serializable?
  
 // class properties
 private String _smackletName;
 private String _smackletTeaseLink;
 private String _smackletLink;
 private String _smackletThumbnail;
 
 // constructor
 
 public SmackletType(String smackletName, String smackletLink, String smackletTeaseLink, String smackletThumbnail) {
   
  _smackletThumbnail = smackletThumbnail;
  _smackletTeaseLink = smackletTeaseLink;
  _smackletLink = smackletLink;
  _smackletName = smackletName;
  
 } // SmackletType constructor

 // getters and setters
 
 public String get_smackletLink() {
  return _smackletLink;
 }

 public void set_smackletLink(String link) {
  _smackletLink = link;
 }

 public String get_smackletName() {
  return _smackletName;
 }

 public void set_smackletName(String name) {
  _smackletName = name;
 }

 public String get_smackletTeaseLink() {
  return _smackletTeaseLink;
 }

 public void set_smackletTeaseLink(String teaseLink) {
  _smackletTeaseLink = teaseLink;
 }

 public String get_smackletThumbnail() {
  return _smackletThumbnail;
 }

 public void set_smackletThumbnail(String thumbnail) {
  _smackletThumbnail = thumbnail;
 }
 
} // SmackletType class


ActionScript Code for SmackletType:

class SmackletType {
 
 // class properties
 private var _smackletName:String;
 private var _smackletTeaseLink:String;
 private var _smackletLink:String;
 private var _smackletThumbnail:String;
 
 // constructor
 
 public function SmackletType(smackletName:String, smackletLink:String, smackletTeaseLink:String, smackletThumb:String) {
  
  _smackletThumbnail = smackletThumb;
  _smackletTeaseLink = smackletTeaseLink;
  _smackletLink = smackletLink;
  _smackletName = smackletName;
  
} // SmackletType constructor
 
 // getters and setters
 public function get smackletName():String {
  return _smackletName;
 }
 
 public function set smackletName(sSmackletName:String):Void {
  _smackletName = sSmackletName;
 }
 
  public function get smackletLink():String {
  return _smackletLink;
 }
 
 public function set smackletLink(sSmackletLink:String):Void {
  _smackletLink = sSmackletLink;
 }
 
 public function set smackletTeaseLink(sSmackletTeaseLink:String):Void {
  _smackletTeaseLink = sSmackletTeaseLink;
 }
 
 public function get smackletTeaseLink():String {
  return _smackletTeaseLink;
 } 
 
  public function get smackletThumbnail():String {
  return _smackletThumbnail;
 }
 
 public function set smackletThumbnail(sSmackletThumbnail:String):Void {
  _smackletThumbnail = sSmackletThumbnail;
 }
 
} // SmackletType class

I have added the following into my openamf-config.xml file:

<custom-class-mapping>
  <java-class>com.flashdb.domain.SmackletType</java-class>
  <custom-class>SmackletType</custom-class>
</custom-class-mapping>

This is the simple piece of java code I have edited to send my object:

package com.flashdb.services;

import com.flashdb.domain.*;

public class HelloWorld {
    
 SmackletType testSmackletType = new SmackletType("Slots", "http://www.google.com", "http://www.google.ca", "00.gif");
 
 public SmackletType makeEcho(){
        return testSmackletType;
    }
 
}

And Finally, the ActionScript code to actually call for the object:

//Import needed classes
import mx.remoting.Service;
import mx.services.Log;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.PendingCall;
import mx.remoting.debug.NetDebug
NetDebug.initialize()
// initialize the Logger
var myLogger : Log = new Log (Log.DEBUG, "logger1" );
// override the default log handler
myLogger.onLog = function (message : String ) : Void {
   trace ("myLogger-->>>" + message );
}

//Create the service
myService = new Service ("http://localhost/helloworld/gateway", myLogger, "com.flashdb.services.HelloWorld", null, null);
Object.registerClass("com.flashdb.domain.SmackletType", SmackletType);
//on Data handler
//function onEchoData (msg : ResultEvent){
function onEchoData (msg : SmackletType){
   mx.remoting.debug.NetDebug.trace ({level : "Debug", message : "onCategoryData" });
//   show.text = msg.result;
   //var temp:SmackletType = msg;
   var temp:SmackletType = msg;
   trace(temp.smackletName() + "            HOOGEY BOOGEY!");
}
//on Error handler
function onEchoFault (rs : ResultEvent){
   mx.remoting.debug.NetDebug.trace ({level : "None", message : "There was a problem: " + fault.fault.faultstring     });
}
//Buttons callbacks
callButton.onPress = function () {
   //create the remoting call
   var pc : PendingCall = myService.makeEcho();
   pc.responder = new RelayResponder (this._parent, "onEchoData",
   "onEchoFault" );
}
//just clear the textfield
clearButton.onPress = function (){
   show.text = "";
}
stop();


When I run my program and hit the "callbutton", I get this...

myLogger-->>>7/4 15:15:2 [INFO] logger1: Creating Service for com.flashdb.services.HelloWorld
myLogger-->>>7/4 15:15:2 [INFO] logger1: Creating gateway connection for http://localhost/helloworld/gateway
myLogger-->>>7/4 15:15:2 [INFO] logger1: Successfully created Service
myLogger-->>>7/4 15:15:3 [INFO] logger1: Invoking makeEcho on com.flashdb.services.HelloWorld
undefined            HOOGEY BOOGEY!
myLogger-->>>7/4 15:15:3 [INFO] logger1: com.flashdb.services.HelloWorld.makeEcho() returned {_smackletLink: "http://www.google.com", 
     _smackletName: "Slots", 
     _smackletTeaseLink: "http://www.google.ca", 
     _smackletThumbnail: "00.gif"}


I just want to be able to get that info that is being passed into Flash to become my SmackletType object. Can anyone give me a hand? This stuff is making my life so much easier right now over web services, and any help I could get would be greatly appreciated.

Thank you!

--LD

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

_______________________________________________
Openamf-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openamf-user