0

我想我真的很菜鸟时刻,我从coldfusion返回一个远程对象,我想指定对象类型。即我从coldfusion 得到一个工人,我有一个价值对象工人。

这是我一直在尝试的

public function ResultHandler_GetWorker(event:ResultEvent):void
{
    var result:ArrayCollection = ArrayCollection(event.result);
    var worker:WorkerVO = WorkerVO(result[0]);
    model.worker = worker;
}

Result[0]是一个雇员对象。它的调试结构看起来像这样。

workerAddress "24b fake Ave"
workerCity "Wellton"
workerCountry "Ameriland" workerEmail "Afake@me.com"
workerFName "Foo"
workerHPhone "435234"
workerID 1
workerImage null
workerIsAdmin true
workerLName "Foo"
workerMPhone "827271903" workerPassword "password"
workerPosition "领导者"
workerState""
workerSuburb"Birkenhead"
workerWPhone null

我的课看起来像这样:

public class WorkerVO
{       
    public var _workerAddress:String
    public var _workerCity:String
    public var _workerCountry:String    
    public var _workerEmail:String  
    public var _workerFName:String  
    public var _workerHPhone:String 
    public var _workerID:uint;  
    public var _workerImage:String
    public var _workerIsAdmin:Number;
    public var _workerLName:String
    public var _workerMPhone:String;
    public var _workerPassword:String;
    public var _workerPosition:String;
    public var _workerState:String;
    public var _workerSuburb:String;
    public var _workerWPhone:String;


    public function WorkerVO()
    {
    }

    //Getters & Setters 
}

错误 #1034:类型强制失败:无法将 Object@114eeb251 转换为 com.cavej03.sitesafe.vo.WorkerVO。

我做错了吗。我只是想创建一个函数或构造函数来接受这个对象并将其字段映射到一个新的 WorkerVO

4

2 回答 2

2

您缺少RemoteClass元数据标记。此标记告诉您的应用程序给定的客户端 VO 映射到哪个服务器端 VO。

像这样使用它:

[RemoteClass(alias="path.to.WorkerVO")]  //this is the servers-side path
public class WorkerVO {
    ...
}

此外,从您所显示的内容来看,您的属性名称似乎不匹配:客户端的名称带有下划线,而服务器端的名称则没有。
客户端 VO 和服务器端 VO 的属性名称应该完全相同。例如:

/* Java VO */
public class WorkerVO {

    private String workerAddress;
    public String getWorkerAddress() { 
       return workerAddress; 
    }
    public void setWorkerAddress(String workerAddress) {
       this.workerAddress = workerAddress;
    }

}

/* ActionScript VO */
[RemoteClass(alias="path.to.WorkerVO")]
public class WorkerVO {

    public var workerAddress:String;

}

这是一个 Java VO 示例,但同样适用于 ColdFusion。

于 2013-04-08T11:16:24.507 回答
0

将返回的对象分配给 内的属性WorkerVO,并为每个对象准备 getter,如下所示:

public class WorkerVO
{

    private var _base:Object;


    public function WorkerVO(base:Object)
    {
        _base = base;
    }


    public function get address():String{ return _base.workerAddress; }
    public function get city():String{ return _base.workerCity; }
    // Etc.

}

而worker的定义只需要new添加关键字即可:

var worker:WorkerVO = new WorkerVO(result[0]);
trace(worker.address);
于 2013-04-08T05:22:15.127 回答