- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="<a href="http://www.adobe.com/2006/mxml">http://www.adobe.com/2006/mxml"
- layout="vertical"
- minWidth="955"
- minHeight="600"
- creationComplete="init()">
- <mx:Script>
- <![CDATA[
- import mx.collections.XMLListCollection;
- [Bindable]private var nationList:XMLListCollection; //国家数据提供源
- [Bindable]private var stateList:XMLListCollection; //省数据提供源
- [Bindable]private var cityList:XMLListCollection; //市数据提供源
- // [Embed(source="fun/1.png")]private var fun1:Class;
- //[Embed(source="fun/2.png")]private var fun3:Class;
- private function init():void
- {
- if(!nationList)
- nationList = new XMLListCollection();
- if(!stateList)
- stateList = new XMLListCollection();
- if(!cityList)
- cityList = new XMLListCollection();
- chose("chinese"); //默认为中文
- }
- //语言选择
- private function chose(type:String):void
- {
- initData(locationCn);
- }
- //初始化数据
- private function initData(location:XML):void
- {
- nationList.source = location.CountryRegion;
- onNationChange();
- onStateChange();
- }
- //国家联动事件
- private function onNationChange():void
- {
- var x:XML = nation.selectedItem as XML;
- //转换时由于联动关系,x值可能为空,此时用list的第一个数据填充
- if(x)
- stateList.source = x.State;
- else
- stateList.source = nationList.source[0].State;
- //如果没有相关的数据则隐藏该combobox
- // if(stateList.length == 0)
- // state.visible = state.includeInLayout = false;
- // else
- // state.visible = state.includeInLayout = true;
- // onStateChange();
- }
- //省联动事件
- private function onStateChange():void
- {
- var x:XML = state.selectedItem as XML;
- //转换时由于联动关系,x值可能为空,此时用list的第一个数据填充
- if(x)
- cityList.source = x.City;
- else
- cityList.source = stateList.source[0].City;
- //如果没有相关的数据则隐藏该combobox
- // if(cityList.length == 0)
- // city.visible = city.includeInLayout = false;
- // else
- // city.visible = city.includeInLayout = true;
- }
- //名字过长,截取显示
- private function shortName(x:XML):String
- {
- var name:String = x.@Name;
- return name.length > 13?name.substr(0,13)+"...":name;
- }
- ]]>
- </mx:Script>
- <mx:XML id="locationCn" format="e4x" source="/abin/renzhi.xml"/>
- <mx:Spacer height="50"/>
- <mx:Image id="funImage"/>
- <mx:HBox horizontalAlign="center" x="0" y="0">
- <mx:ComboBox id="nation" width="120" dataProvider="{nationList}"
- change="onNationChange()" labelFunction="{shortName}" creationComplete="onNationChange()"/>
- <mx:ComboBox id="state" width="120" dataProvider="{stateList}"
- change="onStateChange()" labelFunction="{shortName}" creationComplete="onStateChange()"/>
- <mx:ComboBox id="city" width="120" dataProvider="{cityList}"
- labelFunction="{shortName}"/>
- </mx:HBox>
- </mx:Application>
- <?xml version="1.0" encoding="UTF-8"?>
- <Location>
- <CountryRegion Name="轻度认知功能障碍" Code="1" >
- <State Name="阿尔茨海默源性"/>
- <State Name="血管源性">
- <City Name=""/>
- <City Name="关键部位梗死或大面积卒中导致的血管性"/>
- <City Name="多发卒中性"/>
- <City Name="小血管性"/>
- <City Name="其它血管性"/>
- </State>
- <State Name="混合性"/>
- <State Name="路易体痴呆性"/>
- <State Name="额颞叶痴呆性"/>
- <State Name="帕金森病合并"/>
- <State Name="其它"/>
- </CountryRegion>
- <CountryRegion Name="痴呆" Code="2" >
- <State Name="阿尔茨海默病"/>
- <State Name="血管性痴呆">
- <City Name="关键部位梗死或大面积卒中导致的血管性痴呆"/>
- <City Name="多发卒中性痴呆"/>
- <City Name="小血管性痴呆"/>
- <City Name="其它血管性痴呆"/>
- </State>
- <State Name="混合性痴呆"/>
- <State Name="路易体痴呆"/>
- <State Name="额颞叶痴呆"/>
- <State Name="帕金森病性痴呆"/>
- <State Name="其它痴呆类型"/>
- </CountryRegion>
- </Location>
- //该片段来自于http://www.codesnippet.cn/detail/11122012908.html
来源: http://www.codesnippet.cn/detail/11122012908.html