0
我正在使用BlazeDS將Flex與Java連接。我在遇到麻煩時,我嘗試訪問Java對象字段中的Flex訪問Flex中的Java對象字段BlazeDS
這是我的Java類路徑:
package intetech;
public class Path {
public Path(){
}
public Path(double x1, double y1, double x2, double y2){
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public double getX1(){
return x1;
}
public double getY1(){
return y1;
}
public double getX2(){
return x2;
}
public double getY2(){
return y2;
}
private double x1;
private double y1;
private double x2;
private double y2;
}
而Java類PathsService返回路徑的ArrayList中的getPaths方法:
package intetech;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class PathsService {
public PathsService(){}
public List<Path> getPaths(){
File svgFile = new File("D:\\work\\blazedsTurnkey\\blazeds-turnkey-4.0.0.14931\\tomcat\\webapps\\blazeds\\WEB-INF\\classes\\intetech\\test.svg");
try{
SvgParser svgp = new SvgParser(svgFile);
listOtr = svgp.getList();
} catch (SAXException ex) {
} catch (ParserConfigurationException ex) {
} catch (IOException ex) { }
return listOtr;
}
private static List<Path> listOtr;
}
所以我嘗試從Flex ArrayList中獲取一個路徑的座標。 Main.mxml:
<fx:Declarations>
<!--setup the connection to the Java class-->
<mx:RemoteObject
id="PathsService"
destination="pathsservice"
showBusyCursor="true"
>
<mx:method name="getPaths"
result="resultGetPaths(event)"
fault="faultGetPaths(event)"/>
</mx:RemoteObject>
</fx:Declarations>
<fx:Script>
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;
private var aPath:Path ;
private var pathsArrCol:ArrayCollection;
private var otr:Path;
public function resultGetPaths(event:ResultEvent):void {
pathsArrCol = event.result as ArrayCollection;
**otr = pathsArrCol.getItemAt(0) as Path;
Alert.show(ObjectUtil.toString(otr.getX1()));**
}
private function faultGetPaths(event:FaultEvent):void{
Alert.show(ObjectUtil.toString(event.fault));
}
</fx:Script>
和Path.as文件:
package
{
[RemoteClass(alias="intetech.Path")]
[Bindable]
public class Path
{
private var ax1:Number;
private var ay1:Number;
private var ax2:Number;
private var ay2:Number;
public function getX1():Number {
return ax1;
}
public function getY1():Number {
return ay1;
}
public function getX2():Number {
return ax2;
}
public function getY2():Number {
return ay2;
}
public function setX1(data:Number): void{
ax1 = data;
}
public function setY1(data:Number): void{
ax1 = data;
}
public function setX2(data:Number): void{
ax1 = data;
}
public function setY2(data:Number): void{
ax1 = data;
}
}
}
我有NaN的結果,當我運行該應用程序,請幫助
請問您能解釋一下嗎,我爲每個座標x1,x2,y1,y2添加4個setter,並且什麼也沒有發生 – 2013-03-12 15:17:40
您可以使用您添加的代碼更新您的問題。 – Daedalus 2013-03-12 15:40:31
更新,添加設置器 – 2013-03-12 16:04:00