1包结构
2 Test.mxml
<?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" xmlns:local="*">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<local:UnitedStates width="300">
</local:UnitedStates>
</s:Application>
3UnitedStates.mxml(新建-组件)
<?xml version="1.0" encoding="utf-8"?> <mx:ComboBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" dataProvider="{this.statesCollection}" > <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:ArrayCollection id="statesCollection"> <fx:Object stateCode="AK" label="Alaska"/> <fx:Object stateCode="AL" label="Alabama"/> <fx:Object stateCode="JS" label="江苏"/> </s:ArrayCollection> </fx:Declarations> </mx:ComboBox>
4任何没有直接包含在显示列表中的对象都必须在<fx:Declarations>标签中指定。在组件头声明数据来源
5引用的时候也可以是
<?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" xmlns:control="*"> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <control:UnitedStates width="300"> </control:UnitedStates> </s:Application>
主要是绑定数据的声明问题。要保持一致。