1.as对象属性必须为public的
2.remote调用的java方法时,参数不能作为区别不同方法的依据,也就是说,java方法不
能重名
3.dojo对象,必须有无参构造函数
4.as对象需加[RemoteClass(alias="cn.com.blazeds.test.User")]
以下是我的demo,供同学们参考
1.testHelloWorld.mxml源码
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
[Bindable]
private var memberResult:Object;
private function say():void{
var user:User=new User();
user.setName(n.text);
user.setId("testId");
ro.sayHello1(user);
}
public function handleResult(event:ResultEvent):void {
target.text=event.result as String;
}
]]>
2.HelloWorld.java源码
package cn.com.blazeds.test;
public class HelloWorld {
public String sayHello1(User user) {
System.out.println("**********sayHello(User user) in*************");
return "hello,name: " + user.getName()+",Id:"+user.getId();
}
public String sayHello(String name){
System.out.println("**********sayHello(String name) in*************");
return "hello,"+name;
}
public String sayHello2(String name){
System.out.println("**********sayHello2(String name) in*************");
return "hello2,"+name;
}
public User getUser(String name){
System.out.println("**********getUser in*************");
return new User(name,name+"Id");
}
}
3.User.java源码
package cn.com.blazeds.test;
import java.io.Serializable;
public class User implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private String id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
4.User.as源码
package
{
[RemoteClass(alias="cn.com.blazeds.test.User")]
public class User
{
public var name:String;
public var id:String;
public function getName():String{
return name;
}
public function setName(name:String ):void {
this.name = name;
}
public function getId():String {
return id;
}
public function setId(id:String):void {
this.id = id;
}
}
}