這就是我的做法。我希望你會發現它有用:
public static function getRemoteObject(destination:String, channelName:String,
showBusyCursor:Boolean=true):RemoteObject{
var remoteService:RemoteObject=new RemoteObject(destination);
var channelSet:ChannelSet=new ChannelSet();
var url:String = Application(Application.application).url;
var secure:Boolean = URLUtil.isHttpsURL(url);
var protocol:String = URLUtil.getProtocol(url);
var amf:AMFChannel;
if (secure){
amf = new SecureAMFChannel(channelName, protocol +
"://{server.name}:{server.port}" +
(Application.application as Application).parameters.contextRoot +
"/graniteamf/amf");
}else{
amf = new AMFChannel(channelName, protocol +
"://{server.name}:{server.port}" +
(Application.application as Application).parameters.contextRoot
+ "/graniteamf/amf");
}
channelSet.addChannel(amf);
remoteService.channelSet=channelSet;
remoteService.showBusyCursor=showBusyCursor;
return remoteService;
}
所以你可以看到你需要提供的唯一的東西是目標 - 必須在服務器端的XML和上下文根配置 - 爲Flash變量傳遞。在我的情況下(通過JSP)傳遞flashVar看起來像這樣:
String flashVariables = "contextRoot=" + request.getContextPath() +
"&locale=" + request.getLocale().getLanguage();
來源
2010-12-10 09:27:31
2DH
這太棒了。我得到你如何從Application.url推斷主機名,端口和協議。不過,我是一個JSP新手......你能幫我解決另一個問題嗎?你是說你把你的SWF html包裝器轉換成JSP頁面嗎?或者你把javascript放在調用JSP頁面的html包裝器中?這是如何運作的? – HDave 2010-12-10 14:20:24