Re: OpenAMF with AS2

[email protected]
Newsgroups gmane.comp.java.openamf.user
Message-ID <[email protected]>
 
Jason,
 
The problem you have is that standard objects cannot be sent from java to  
flash directly. You need to use an object called ASObject, which needs to be  
imported. I am currently using the macromedia gateway so the import function may 
 be a little different than the openAMF, but you should be able to find the  
definition in the openAMF project and import it as I show below. the second  
parameter of the ASObject.put routine can take simple data types or complex 
ones  such as resultsets. 
 
There is also a function called ASTranslator (find on google at souceforge  
or carbonfive) that translates any java object into a flash object.
 
I just figured all this stuff out yesterday, and the weird thing is that  
there is, as far as I can tell, no official documentation on ASObject (at least  
from macromedia or anywhere on the web), but lots of people seem to know how 
to  do it. I saw some example somewhere, but would love to find a full 
description  of all the methods and properties. I don't know how macromedia succeeds 
with  such poor documentation of such basic things.
 
Anyway, hope this helps.
 
Hank
 
-----------------------------------------------------------------------
uncompiled code example using ASObject ----------
 
import flashgateway.io.*;
 
class getPersonClass {
    public static ASObject getPerson  (){
ASObject  person =  new  ASObject();
person.put("firstName",  "sam");
person.put("lastName",  "smith");
 
      return  person;
}

}
 
-----------------------------------------------------------------------
Example of ASTranlator from carbon five-------------

package com.server;
 
 import flashgateway.io.ASObject;
 import com.carbonfive.flash.ASTranslator;
   
 public class Service
 {
   public ASObject getPlayer(String name)
   {
     Player player = Roster.getPlayer(name);
     ASObject aso = (ASObject) new ASTranslator().toActionScript(player);
     return aso;
   }
 }

-------------------------------------

 
In a message dated 10/30/2004 12:56:12 A.M. Eastern Daylight Time,  
[email protected] writes:

Hi,

I tried to use OpenAMF with ActionScript2 using a simple  example.  The 
result displayed on the screen was "undefined  undefined".  JDK version used 
was 1.4.1.  I post the log, source  codes, and code scriptlet in the 
configuration file here.  Would  anyone help to figure out what went wrong?

Thanks in  advance!

Jason


[29/10/04 21:34:18:170 EDT] 69f057e9  AMFDeserializ I 
org.openamf.io.AMFDeserializer  Deserializing  Message, for more info turn on 
debug level

[29/10/04 21:34:18:185  EDT] 69f057e9 REQUEST       I org.openamf.REQUEST   
REQUEST:
[AMFBody: {serviceName=org.openamf.examples.PersonService,  
serviceMethodName=readPerson, response=/1, type=ARRAY,  value=[]}]

[29/10/04 21:34:18:185 EDT] 69f057e9 JavaServiceIn I  
org.openamf.invoker.JavaServiceInvoker  topRankedMethod:  name=readPerson 
rank=100.0

[29/10/04 21:34:18:185 EDT] 69f057e9  RESPONSE      I org.openamf.RESPONSE   
RESPONSE:
[AMFBody: {serviceName=null, serviceMethodName=null,  response=null, 
type=UNKNOWN, value=Elmar Fudd, zipcode =  12345}]

[29/10/04 21:34:18:185 EDT] 69f057e9 AMFSerializer I  
org.openamf.io.AMFSerializer  Serializing Message, for more info turn  on 
debug level


####Client2.as######

import  mx.remoting.NetServices;
import mx.controls.*;

class Client2 extends  mx.screens.Form {
var inited:Boolean;
var  conn:NetConnection;
var personService:Object;
var person:Person;
var display_btn:Button;
var name_txt:TextArea;
function Client2() {
super();
}
public  function init():Void {
trace("tracing init()  function..");
if (inited == null) {
inited = true;
// connect to a gateway
conn =  
NetServices.createGatewayConnection("http://localhost:8080/openamf/gateway");
//  create a service object that  points to your java class acting as a 
service
personService =  conn.getService("org.openamf.examples.PersonService", 
this);
}
display_btn.onPress =  function() {
_parent.personService.readPerson();
}
}
// function specific result handler  objects
public function readPerson_Result(result):Void  {
// display successful result
name_txt.text = result.getFirstName()+ " "+  result.getLastName();
}
public function  readPerson_Fault(fault):Void {
trace("Error  receiving Person: "+fault.faultstring);
}
}

####PersonService.java#####
package  org.openamf.examples;

public class PersonService {


public PersonService() {
super();

}
public Person readPerson()  {

Person person = new  Person();

person.setFirstName("Elmar");
person.setLastName("Fudd");

return  person;
}
}


####openamf-config.xml####
<amf-serializer>
<force-lower-case-keys>false</force-lower-case-keys>
</amf-serializer>
<custom-class-mapping>
<java-class>org.openamf.examples.Person</java-class>
<custom-class>Person</custom-class>
</custom-class-mapping>

<service>
<name>PersonService</name>
<service-location>org.openamf.examples.PersonService</service-location>
<invoker-ref>java</invoker-ref>
<method>
<name>*</name>
<parameter>
<type>*</type>
</parameter>
</method>
</service>

_________________________________________________________________
Scan  and help eliminate destructive viruses from your inbound and outbound  
e-mail and attachments.  
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http:
//hotmail.com/enca&HL=Market_MSNIS_Taglines  
Start enjoying all the benefits of MSN® Premium right now and get  the 
first two months  FREE*.



-------------------------------------------------------
This  SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download  now for FREE
LinuxWorld Reader's Choice Award Winner for best database on  Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Openamf-user  mailing  list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openamf-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.