Sample application for help TextInput.
package com.abc.components
{
import flash.events.Event;
import flash.events.FocusEvent;
import mx.controls.TextInput;
public class HelpTextInput extends TextInput
{
private var _label:String;
private var _isTextSet:Boolean;
public function HelpTextInput()
{
//TODO: implement function
super();
}
/* */
public function get label():String
{
return this._label;
}
/* */
public function set label(value:String):void
{
_isTextSet = false;
this._label = value;
updateField();
}
/* */
override public function set text(value:String):void
{
if(value == "")
{
_isTextSet = false;
}
else
{
_isTextSet = true;
super.text = value;
}
updateField();
}
/* */
[Bindable]
override public function get text():String
{
if(!_isTextSet)
{
return "";
}
else
{
return super.text;
}
}
/* */
private function updateField():void
{
if(_isTextSet)
{
setStyle('color', 0x000000);
}
else
{
super.text = _label;
setStyle('color', 0xaaaaaa);
}
}
/* */
private function onChange( event:Event ):void
{
if(super.text == "")
{
_isTextSet = false;
}
else
{
_isTextSet = true;
}
}
/* */
private function onFocuIn( event:FocusEvent ):void
{
if(!_isTextSet)
{
setStyle('color', 0x000000);
super.text = "";
}
}
/* */
private function onFocusOut( event:FocusEvent ):void
{
updateField();
}
/* */
override public function initialize():void
{
super.initialize();
addEventListener(Event.CHANGE, onChange);
addEventListener(FocusEvent.FOCUS_IN, onFocuIn);
addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
updateField();
}
}
}
The mxml part
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" xmlns:components="com.abc.components.*">
<mx:Label text="Text" />
<components:HelpTextInput label="Enter firstname" />
<components:HelpTextInput label="Enter lastname" />
</mx:WindowedApplication>
No comments:
Post a Comment