English 中文(简体)
我怎么在Flex从配置文件读取吗?
原标题:
  • 时间:2009-04-16 00:12:01
  •  标签:

现在我工作在一个项目为学校和我们试图把它设置,这样就很容易部署。webapp的部分完全是用Adobe flex编写。

然而,我们需要在代码中某些文件/链接url年代是不同的在不同的机器上。

For instance, my server might use 8180 as the port while someone else uses 8080. Or one person is using Windows so a filepath would be C:/... while mine would be /home/...

有什么方法我们可以把这些文件到一个单独的配置文件和读取动态地在mxml文件?

这将是很好的如果我们没有t必须编译为每个部署……

提前谢谢!

问题回答

您可以使用HTTPService加载XML文件因为(或任何文本文件)的位置相对于Flex应用程序SWF。在应用程序启动时只需执行中的HTTPService,解析文件,并在需要的地方提供的数据。

查看< a href = " http://code.google.com/p/appcorelib/ " rel = " nofollow noreferrer " > appcorelib < / >,文档将向您展示如何使用相对URL,如从一个资产文件夹:

loadXML("assets/xml/config.xml);

不需要担心crossdomain如果xml和flex应用程序在相同的服务器。

(如果已启用本地文件盒,你可以使用URLLoader读取本地文件:

< a href = " http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=05B_Security_176_04.html " rel = " nofollow noreferrer " > http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=05B_Security_176_04.html < / >

然而,SWF也必须是本地的。

如果你是远程加载SWF,您可以连接到加载服务器资源的列表。在大多数情况下,应该是首选的解决方案。

You can pass in parameters into a SWF by adding FlashVars to the HTML that it s running from. FLashVars

我强烈同意brd6644。你需要一个跨域策略文件服务器上的配置文件驻留的地方。复制下面的XML文件名为“crossdomain。xml”并把它放在服务器的根服务器,其中包含您的配置文件。

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy 
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*" />
</cross-domain-policy>

你可能不需要这个如果swf驻留在同一台服务器上的配置文件。也,如您所见,这个跨域策略允许访问所有领域,所以,如果你非常关心安全(可能不是重要的学校项目),读了些关于他们如何配置。这是一个很好的< a href = " http://labs.adobe.com/wiki/index.php/Flex Accessing_Data # Using_crossdomain.xml_files”rel = " nofollow noreferrer " > < / >的文章

同时,这里有一些样本HTTPService代码:因为

private function init():void{
     get_bands_service.url = yeswewillArtistsURL;
     get_bands_service.method = "GET";
     get_bands_service.addEventListener(FaultEvent.FAULT, onServiceFault);
     get_bands_service.requestTimeout = 20;
     get_bands_service.send();
}

<mx:HTTPService id="get_bands_service" result="parseBandsServiceResult();" useProxy="false" />




相关问题
热门标签