1  /**
     2   * com.sekati.display.TextDisplay
     3   * @version 1.1.0
     4   * @author jason m horwitz | sekati.com | tendercreative.com
     5   * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  
     9  import com.sekati.core.App;
    10  import com.sekati.effects.TextEffects;
    11  import com.sekati.effects.AnimHandler;
    12  import com.sekati.transitions.Mot;
    13  import com.sekati.validate.TypeValidation;
    14  
    15  /**
    16   * TextDisplay - utilities for uniformly styling, clearing, and animating text in display clip classes.
    17   */
    18  class com.sekati.display.TextDisplay {
    19  
    20  	/**
    21  	 * Clear all textfields in the object
    22  	 * @param o (MovieClip)
    23  	 * @return Void
    24  	 */	
    25  	public static function clear(o:MovieClip):Void {
    26  		for(var i in o) { 
    27  			if (TypeValidation.isTextField( o[i] )) o[i].htmlText = ""; 
    28  		}			
    29  	}
    30  
    31  	/**
    32  	 * Apply the App.css stylesheet to all textfields in the object.
    33  	 * @param o (MovieClip)
    34  	 * @return Void
    35  	 */
    36  	public static function style(o:MovieClip):Void {
    37  		for(var i in o) { 
    38  			if (TypeValidation.isTextField( o[i] ) && !o[i].styleSheet) o[i].styleSheet = App.css; 
    39  		}		
    40  	}
    41  
    42  	/**
    43  	 * Apply stylesheet to text and intro string.
    44  	 * @param tf (TextField)
    45  	 * @param str (String)
    46  	 * @return Void
    47  	 */
    48  	public static function show(tf:TextField, str:String):Void {
    49  		if (!tf.styleSheet) tf.styleSheet = App.css;
    50  		tf.htmlText = str;
    51  	}
    52  
    53  	/**
    54  	 * Hide a textfield (visible false, alpha 0)
    55  	 * @param o (Array) - array of textfields or individual field
    56  	 * @param isAnim (Boolean) - animate the transition
    57  	 * @return Void
    58  	 * @see TextDisplay.reveal()
    59  	 */
    60  	public static function hide(o:Array, isAnim:Boolean):Void {
    61  		if (TypeValidation.isArray( o )) {
    62  			for(var i:Number = 0; i < o.length ; i++) { 
    63  				if (TypeValidation.isTextField( o[i] )) {
    64  					o[i].stopTween( );
    65  					if (!isAnim) {
    66  						o[i]._alpha = 0;
    67  						o[i]._visible = false;
    68  					} else {
    69  						o[i].alphaTo( 0, 1, Mot.o.quint, 0.1 * i, function():Void { 
    70  							o[i]._visible = false; 
    71  						} );	
    72  					}
    73  				}
    74  			}	
    75  		}
    76  	}
    77  
    78  	/**
    79  	 * Reveal a textfield (visible true, alpha 100)
    80  	 * @param o (Array) - array of textfields
    81  	 * @param isAnim (Boolean) - animate the transition
    82  	 * @return Void
    83  	 * @see TextDisplay.hide()
    84  	 */
    85  	public static function reveal(o:Array, isAnim:Boolean):Void {
    86  		if (TypeValidation.isArray( o )) {
    87  			for(var i:Number = 0; i < o.length ; i++) { 
    88  				if (TypeValidation.isTextField( o[i] )) {
    89  					o[i].stopTween( );
    90  					if(!isAnim) {
    91  						o[i]._alpha = 100;
    92  						o[i]._visible = true;
    93  					} else {
    94  						o[i]._visible = true;
    95  						o[i].alphaTo( 100, 0.3, Mot.o.quint, 0.1 * i );							
    96  					}
    97  				}
    98  			}	
    99  		}
   100  	}
   101  
   102  	/**
   103  	 * anim text - atype wrapper.
   104  	 * @param tf (TextField)
   105  	 * @param str (String)
   106  	 * @param cb (Function)
   107  	 * @return Void
   108  	 */
   109  	public static function anim(tf:TextField, str:String, cb:Function):Void {
   110  		if (!tf.styleSheet) tf.styleSheet = App.css;
   111  		TextEffects.atype( tf, str, cb );
   112  		//TextEffects.pushtype(tf, str, 10, true, cb);
   113  	}
   114  
   115  	/**
   116  	 * anim text - push wrapper.
   117  	 * @param tf (TextField)
   118  	 * @param str (String)
   119  	 * @param ms (Number)
   120  	 * @param cb (Function)
   121  	 * @return Void
   122  	 */	
   123  	public static function push(tf:TextField, str:String, ms:Number, cb:Function):Void {
   124  		if (!tf.styleSheet) tf.styleSheet = App.css;
   125  		var t:Number = (!ms) ? 10 : ms;
   126  		TextEffects.pushtype( tf, str, t, true, cb );		
   127  	}
   128  
   129  	/**
   130  	 * stop tween wrapper.
   131  	 * @param tf (TextField)
   132  	 * @return Void
   133  	 */
   134  	public static function stopEffect(tf:TextField):Void {
   135  		AnimHandler.destroy( tf );
   136  	}
   137  
   138  	private function TextDisplay() {
   139  	}
   140  }