【原创】Flex4 自定义FormItem

package com.founder.tbm.components
{
	import org.osmf.layout.HorizontalAlign;
	
	import spark.components.Group;
	import spark.components.Label;
	import spark.components.SkinnableContainer;
	import spark.layouts.HorizontalLayout;

	public class ItemForm extends SkinnableContainer
	{
		public function ItemForm()
		{
			super();
			setStyle("skinClass", ItemFormSkin);
		}
		
		[SkinPart(required="false")]
		[Inspectable(environment="none")]
		public var labelDisplay:Label;
		
		[SkinPart(required="false")]
		[Inspectable(environment="none")]
		public var requiredDisplay:Label;
		
		private var _label:String;
		
		public function set label(value:String):void
		{
			if (value != _label) 
			{		
				_label = value;
				if (labelDisplay) 
				{		
					labelDisplay.text = value;
				}
			}
		}
		
		public function get label():String
		{
			return _label;
		}
		
		private var _required:Boolean;
		
		public function set required(value:Boolean):void
		{
			if(value != _required)
			{
				_required = value;
				if(requiredDisplay)
				{
					requiredDisplay.visible = value;
				}
			}
		}
		
		public function get required():Boolean
		{
			return _required;
		}
		
		private var _labelWidth:Number;
		
		public function set labelwidth(value:Number):void
		{
			if (value != _labelWidth) 
			{
				_labelWidth = value;
				if (labelDisplay) 
				{		
					labelDisplay.width = value;
				}
			}
		}
		
		public function get labelwidth():Number
		{
			return _labelWidth;
		}
		
		protected override function partAdded(partName:String, instance:Object):void
		{
			super.partAdded(partName, instance);
			
			if (instance == labelDisplay)
			{
				labelDisplay.text = label;
                   if(_labelWidth)
				  labelDisplay.width = _labelWidth;
			}				
			else if (instance == requiredDisplay)
			{
				requiredDisplay.visible = required;
				requiredDisplay.includeInLayout = required;
			}				
		}
	
	}
}

  皮肤文件







	[HostComponent("com.founder.tbm.components.ItemForm")]
	
	
        
        
    
	
	
		
	
    
    
    
        
            
            
        
    
    
    
    
   
	
	
	
	
	
		
			
		
	

  

你可能感兴趣的:(【原创】Flex4 自定义FormItem)