Posted By

blainejoubert on 08/04/09


Tagged

class String text to length long add of TextField end Clipper replaceText


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Demian


Text String Clipper class


 / Published in: ActionScript 3
 

  1. /**
  2.   Text String Clipper class
  3.   author: Blaine Joubert
  4.   version: 0.1
  5.   modified: 04/08/2009
  6.  
  7.  
  8. Adds a ... to the end of a text string if its too long
  9.  
  10. To use: Import Class then use
  11. var textClip:TextClipper = new TextClipper (cutOffCharLength, textFieldName, textFieldCharLength, textContent)
  12.  
  13. */
  14.  
  15. package {
  16. import flash.display.*;
  17. import flash.text.*;
  18.  
  19.  
  20. public class TextClipper extends MovieClip {
  21.  
  22. //--------------------------------------
  23. // PUBLIC VARIABLES
  24. //--------------------------------------
  25.  
  26. public var _cutOffCharLength:int
  27. public var _textFieldName:TextField
  28. public var _textFieldCharLength :int
  29. public var _textContent:String
  30.  
  31. //--------------------------------------
  32. // CONSTRUCTOR
  33. //--------------------------------------
  34.  
  35. public function TextClipper(cutOffCharLength:int, textFieldName:TextField, textFieldCharLength:int, textContent:String ):void {
  36.  
  37. _cutOffCharLength = cutOffCharLength;
  38. _textFieldName = textFieldName;
  39. _textFieldCharLength = textFieldCharLength;
  40. _textContent = textContent;
  41.  
  42. Init();
  43.  
  44. }
  45.  
  46. public function Init():void {
  47.  
  48.  
  49.  
  50. if (_textFieldCharLength >= _cutOffCharLength) {
  51.  
  52. _textFieldName.replaceText(_cutOffCharLength, _textFieldCharLength, "...");
  53.  
  54. }else {
  55.  
  56. _textFieldName.text = _textContent
  57. }
  58.  
  59. }
  60. }
  61.  
  62. }

Report this snippet  

You need to login to post a comment.