com.neolao.textfield.TextFieldUtils

Méthodes

Visibilité Return Nom Param 1 Description
static public Void truncateToField pTarget:TextField Tronque le texte pour que ca rentre dans le champ de texte

Source

/**
 * Méthodes utiles liées aux champs de texte
 * @author 		neo-lao
 * @version 		1.0 (26/07/2005)
 * @link		http://resources.neolao.com/flash/classes/textfield/TextFieldUtils
 * @license		http://creativecommons.org/licenses/by-sa/2.0/
 */
class com.neolao.textfield.TextFieldUtils {
	static public var className:String = "TextFieldUtils";
	static public var version:String = "1.0";
 
	// ----------------------------- CONSTANTES --------------------------------
 
	// ----------------------------- VARIABLES ---------------------------------	
 
	/*=========================== METHODES PRIVEES ===========================*/
	/*========================================================================*/
 
	/*===================== FIN = METHODES PRIVEES = FIN =====================*/
	/*========================================================================*/
 
	/*============================ GETTER  SETTER ============================*/
	/*========================================================================*/
 
	/*====================== FIN = GETTER  SETTER = FIN ======================*/
	/*========================================================================*/
 
	/*========================== METHODES PUBLIQUES ==========================*/
	/*========================================================================*/
	/**
	 * Tronque le texte pour que ca rentre dans le champ de texte
	 * @param pTarget Le champ de texte
	 */
	static public function truncateToField(pTarget:TextField):Void{
		var vFormat:TextFormat = pTarget.getTextFormat();
		var vText:String = pTarget.text;
		var vSize:Object = vFormat.getTextExtent(vText);
		var vBackground:Boolean = pTarget.background;
 
		// on vérifie pour chaque caractère enlevé
		while(pTarget != undefined && vSize.textFieldWidth >= pTarget._width){
			vText = vText.substr(0, vText.length - 1);
			vSize = vFormat.getTextExtent(vText)
		}
 
		pTarget.text = vText;
		pTarget.hscroll = 0;
		pTarget.background = vBackground;
	}
	/*==================== FIN = METHODES PUBLIQUES = FIN ====================*/
	/*========================================================================*/
}