Customize Component-Combox

--CbRegion.as--
package com.flexsolutions.chapter1

{

	import mx.controls.ComboBox;



	public class CbRegion extends ComboBox

	{

			private var lazio:Array=new Array["Roma","Frosinone",
"Rieti", "Latina", "Viterbo"];

			private var tuscany:Array=new Array("Arezzo", "Firenze",
"Grosseto" , "Livorno" , "Lucca","Massa-Carrara" ,"Pisa" , "Pistoia", "Prato", "Siena");;

		}

			private var allRegions:Array=lazio.concat(tuscany);

			private var region:String = "all";

			[Inspectable(defaultValue="all",enumeration=lazio,tuscany,all)]

			//You use the <mx:Metadata> tag to insert metadata tags in an MXML file. 

			//Metadata tags provide information to the Flex compiler that describes how your MXML components are used in a Flex application.

			// Metadata tags do not get compiled into executable code, but provide information to control how portions of your code get compiled

			

			public function set chooseRegion(regionParam:String):void{

			 region=regionParam;

			 if(region="lazio"){

			 	this.dataProvider = lazio;

			 }else if(region="tuscany"){

			 	this.dataProvider = tuscany;

			 }else{

			 	this.dataProvider = allRegions;

			 }

			}

			public function get chooseRegion(){

				return region;

			}

			//Getter and setter methods are accessor methods that enable you to change private

//class properties and make them read-only and write-only. These methods can be

//invoked outside the class and give you the ability to create properties with sophisti-

//cated functionality that you can access like simple properties.

		public function CbRegion()

		{

			

	}

}
--Test.mxml--
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="com.flexsolutions.chapter1.*">
 <!--The file will contain only the native namespace mx. However, to be able to access
the ActionScript class, you have to first create a custom namespace on the
Application tag xmlns:comp="com.flexsolutions.chapter1.*"-->
<mx:Panel x="101" y="79" width="250" height="200" layout="absolute">
  <comp:CbRegion id="mycom" chooseRegion="lazio" x="35" y="87"/>
  
 </mx:Panel>
 <mx:Text x="374.5" y="123" text="1111" width="111" height="40"/>
</mx:Application>
--advance Program--
Des:add radio buttons to permit the user to select the data provider to use on the ComboBox:
<mx:RadioButtonGroup id="regionType" itemClick="mycom.changeRegion(event.currentTarget.selecetedValue)"/>
  <mx:RadioButton x="10" y="56" label="lazio" groupName="regionType" />
  <mx:RadioButton x="10" y="82" label="tuscany" groupName="regionType" />
  <mx:Text x="10" y="132" text="Text is{mycom.chooseRegion()}" width="139"/>
<!--CbRegion.as-->
[Bindable(event="changeRegionEvt")]
//This event is registered by the metadata [Bindable], which is declared on the getter functions chooseRegion() and changeRegion():
  public function changeRegion(regionParam:String){
   region=regionParam;
   if(region=="lazion"){
    this.dataProvider=lazion;
   }else if(region=="tuscany"){
    this.dataProvider = tuscany;
   }else{
    this.dataProvider = allRegions;
   }
   dispatchEvent(new Event("changeRegionEvt"));
  }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值