flex動態設定RemoteObject endpoing,flex遍曆object
在flex開發中經常碰到使用者部署項目時跟開發時的項目名稱不一樣.但flex是編譯時間產生的endpoing,換個名稱部署項目flex就不能訪問服務.
解決辦法:
使用jsp擷取當前項目名及路徑.使用flex調用js的方法,擷取項目的路徑及名稱.修改endpoint
具體源碼如下:
Flex:
<s:RemoteObject id="IndexServicesController" destination="IndexServicesController" fault="httpServiceFault(event)"endpoint="{endpoint}/messagebroker/amf"><s:method name="getSysMenu" result="getSysMenuResultHandler(event)" /></s:RemoteObject>
override protected function createChildren():void {if(ExternalInterface.available){endpoint = ExternalInterface.call("getEndopint");}super.createChildren();}
[Bindable]private var endpoint:String = "";
JSP:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<script type="text/javascript">function getEndopint(){return "<%=basePath%>";}</script>