在Flex中用XML填充组合框
我试图用XML文件中的国家填充一个组合框。不幸的是,组合框没有被填充。我应该如何解决这个问题?提前谢谢 这是我的密码:在Flex中用XML填充组合框,xml,apache-flex,combobox,httpservice,Xml,Apache Flex,Combobox,Httpservice,我试图用XML文件中的国家填充一个组合框。不幸的是,组合框没有被填充。我应该如何解决这个问题?提前谢谢 这是我的密码: protected function navigatorcontent2_creationCompleteHandler(event:FlexEvent):void { fillCboCountries.addEventListener(ResultEvent.RESULT, fillCombobox); fillCboCountries.send();
protected function navigatorcontent2_creationCompleteHandler(event:FlexEvent):void
{
fillCboCountries.addEventListener(ResultEvent.RESULT, fillCombobox);
fillCboCountries.send();
}
protected function fillCombobox(event:ResultEvent):void
{
cboCountries.dataProvider=event.result.global.countryItem;
}
<fx:Declarations>
<s:HTTPService id="fillCboCountries" url="https://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php"/>
</fx:Declarations>
<s:ComboBox id="cboCountries" x="10" y="414" width="173" labelField="countryLabel"/>
受保护的函数navigatorcontent2\u creationCompleteHandler(事件:FlexEvent):无效
{
fillCboCountries.addEventListener(ResultEvent.RESULT,fillCombobox);
fillcboccountries.send();
}
受保护的函数fillCombobox(事件:ResultEvent):void
{
cboCountries.dataProvider=event.result.global.countryItem;
}
在看不到服务调用的XML响应的情况下,我唯一能建议的是将HTTPService
上的设置为“e4x”:
这告诉HTTPService响应是XML,并且您希望使用e4x表达式获取数据。您的代码没有错误。我已将其粘贴到我的空项目中,并在组合框中看到您的字段 我唯一改变的是http,而不是https 所以问题在于数据源,而不是源代码!尝试不使用https
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="navigatorcontent2_creationCompleteHandler(event)">
<fx:Declarations>
<s:HTTPService id="fillCboCountries" url="http://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
protected function navigatorcontent2_creationCompleteHandler(event:FlexEvent):void
{
fillCboCountries.addEventListener(ResultEvent.RESULT, fillCombobox);
fillCboCountries.send();
}
protected function fillCombobox(event:ResultEvent):void
{
cboCountries.dataProvider=event.result.global.countryItem;
}
]]>
</fx:Script>
<s:ComboBox id="cboCountries" x="10" y="414" width="173" labelField="countryLabel"/>
</s:Application>
谢谢大家的帮助
我通过将代码复制到一个新项目中解决了这个问题。不幸的是,我不知道最初的项目出了什么问题。您能发布您的XML结构吗?到真实数据的路径可能有问题。嗨,我的XML是这样的:。。。。。。。。。。。。。1阿富汗。。。。。。。。。。。。。。2阿尔巴尼亚。。。。。。。。。。。。。。。。。。。。。。。确认<代码>https://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php不可用,但是,它是用http:打开的。谢谢,源代码对我也是可用的,但是在我的代码中有一个http请求,我得到了这个错误:RPC Fault faultString=“http request error”faultCode=“Server.error.request”faultDetail=“error:[IOErrorEvent type=“ioError”bubbles=false cancelable=false eventPhase=2 text=“Error#2032:流错误。URL:.URL:这可能是安全设置的问题。这是Flex沙盒的问题。通常,crossdomain.xml文件会有所帮助。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="navigatorcontent2_creationCompleteHandler(event)">
<fx:Declarations>
<s:HTTPService id="fillCboCountries" url="http://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
protected function navigatorcontent2_creationCompleteHandler(event:FlexEvent):void
{
fillCboCountries.addEventListener(ResultEvent.RESULT, fillCombobox);
fillCboCountries.send();
}
protected function fillCombobox(event:ResultEvent):void
{
cboCountries.dataProvider=event.result.global.countryItem;
}
]]>
</fx:Script>
<s:ComboBox id="cboCountries" x="10" y="414" width="173" labelField="countryLabel"/>
</s:Application>