创建组件,代码如下所示:
1 <!-- StateComboBox.mxml -->
2 <?xml version="1.0" encoding="utf-8"?>
3 <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml">
4 <mx:dataProvider>
5 <mx:String>上海</mx:String>
6 <mx:String>深圳</mx:String>
7 <mx:String>北京</mx:String>
8 <mx:String>广州</mx:String>
9 </mx:dataProvider>
10 </mx:ComboBox>
使用创建的组件,代码如下所示:2 <?xml version="1.0" encoding="utf-8"?>
3 <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml">
4 <mx:dataProvider>
5 <mx:String>上海</mx:String>
6 <mx:String>深圳</mx:String>
7 <mx:String>北京</mx:String>
8 <mx:String>广州</mx:String>
9 </mx:dataProvider>
10 </mx:ComboBox>
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
3 xmlns:MyComp="*">
4 <mx:Script>
5 <![CDATA[
6 import mx.controls.Alert;
7
8 private function handleCloseEvent(e:Event):void
9 {
10 Alert.show(e.target.value);
11 }
12 ]]>
13 </mx:Script>
14 <MyComp:StateComboBox rowCount="5" close="handleCloseEvent(event);" />
15 </mx:Application>
代码说明:2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
3 xmlns:MyComp="*">
4 <mx:Script>
5 <![CDATA[
6 import mx.controls.Alert;
7
8 private function handleCloseEvent(e:Event):void
9 {
10 Alert.show(e.target.value);
11 }
12 ]]>
13 </mx:Script>
14 <MyComp:StateComboBox rowCount="5" close="handleCloseEvent(event);" />
15 </mx:Application>
- xmlns:MyComp="*":这是调用组件的代码段,MyComp表示Namespace。后面的是路径,“*”表示同级目录。
最终的效果如下所示:
转自:http://www.cnitblog.com/Lalo/archive/2007/12/24/38010.html