TextInput中设置图标

阅读更多
package
{
	import flash.display.DisplayObject;
	
	import mx.controls.Image;
	import mx.controls.TextInput;
	import mx.core.mx_internal;
	
	use namespace mx_internal;
	
	public class MyTextInput extends TextInput
	{
		private var _image:Image;
		
		public function MyTextInput()
		{
			super();
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			_image = new Image();
			_image.source = "search.png";
			
			addChild(DisplayObject(_image));
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			this._image.width = 16;
			this._image.height = 16;
			
			this._image.x = 0;
			this._image.y = (this.height - this._image.height)/2;
			
			this.textField.x = this._image.width+2;
			this.textField.y = (this.height - this.textField.height)/2;
			this.textField.width = this.width - this._image.width-5;
			//this.setStyle("paddingLeft",this._image.width+2);
			
			
		}
	}
}


比较简单的实现方式了,不过在网上很少查到。这个还是在外网blog上查到的,自己修改了下,本身它是仿照mac 的搜索做的图标在右边,改成左边了。谁要有跟好的解决方案,拿出来研究下啊!!!!o(∩_∩)o 哈哈

你可能感兴趣的:(textinput,image,flex)