Posted By

todbertuzzi on 01/11/08


Tagged

random text


Versions (?)

RandomText AS2


 / Published in: ActionScript
 

URL: http://www.wave9.it/showthread.php?p=123602#post123602

  1. class RandomText extends MovieClip{
  2.  
  3. //***********************************************************************************
  4. // by Albo
  5. //
  6. // Genera una animazione di caratteri randomizzati fino al completamento del
  7. // testo specificato passato come parametro del metodo setRandomText
  8. // _________________________________________________________________________________
  9. //
  10. // USO:
  11. //
  12. // /* non embedded fonts */
  13. // import RandomText;
  14. // var rt:RandomText = new RandomText();
  15. // rt.setTarget(mc);
  16. // rt.setFontValues("Arial", 40, "left", 0xCCCCCC, true, null);
  17. // rt.setRandomText("This is my text...");
  18. //
  19. // /* embedded fonts */
  20. // var rt:RandomText = new RandomText();
  21. // rt.setTarget(mc);
  22. // rt.setFontValues("Myriad Web Pro", 20, "left", 0xCC0000, true, "advanced");
  23. // rt.setRandomText("This is a random text...");
  24. //
  25. //
  26. //***********************************************************************************
  27.  
  28. // Inizializzazione oggetto TextFormat
  29. var myFont:String;
  30. var myFontSize:Number;
  31. var myTextAlign:String;
  32. var myFontColor:Number;
  33.  
  34. // Inizializzazione oggetto target MovieClip
  35. var objTarget:Object;
  36.  
  37. // Inizializzazione oggetto TextField
  38. var myBold:Boolean;
  39. var embFonts:Boolean;
  40. var antialias:String;
  41.  
  42. // Inizializzazione parametro
  43. var stringa:String;
  44.  
  45.  
  46. //***********************************************************************************
  47. //
  48. // Setta i valori per il textformat: tipo di font, dimensione, allineamento,
  49. // colore, grassetto, incorporamento font,
  50. // tipo di antialias
  51. //
  52. //***********************************************************************************
  53.  
  54. function setFontValues(_font, _fontSize, _textAlign, _fontColor, _bold, _embFonts, _antialias) {
  55. this.myFont = _font;
  56. this.myFontSize = _fontSize;
  57. this.myTextAlign = _textAlign;
  58. this.myFontColor = _fontColor;
  59. this.myBold = _bold;
  60. this.embFonts = _embFonts;
  61. this.antialias = _antialias;
  62. }
  63.  
  64.  
  65. //***********************************************************************************
  66. //
  67. // Setta il target della mc contenitore della mc che contiene il testo da randomizzare
  68. //
  69. //***********************************************************************************
  70.  
  71. function setTarget(_objTarget) {
  72. this.objTarget = _objTarget;
  73. }
  74.  
  75. //***********************************************************************************
  76. //
  77. // Metodo setRandomText: passare come parametro la stringa da randomizzare
  78. //
  79. //***********************************************************************************
  80. function setRandomText(_stringa){
  81.  
  82. this.stringa = _stringa;
  83.  
  84. var random_mc:MovieClip = this.objTarget.createEmptyMovieClip("random_mc", objTarget.getNextHighestDepth());
  85.  
  86. var format_fmt:TextFormat = new TextFormat();
  87. format_fmt.font = this.myFont;
  88. format_fmt.size = this.myFontSize;
  89. format_fmt.align = this.myTextAlign
  90. format_fmt.color = this.myFontColor;
  91. format_fmt.bold = this.myBold;
  92.  
  93. var speed:Number = 10;
  94. var pausa:Number = 70;
  95. var len:Number = stringa.length;
  96. var counter:Number = 0;
  97. var go:Number = getTimer() + pausa;
  98. var max:Number = 97;
  99. var min:Number = 123;
  100. var intervallo:Number;
  101. var str:String = undefined;
  102.  
  103. random_mc.createTextField("random_txt", random_mc.getNextHighestDepth(), null, null, null, null);
  104.  
  105. function setMatrixText(_stringa){
  106. str = _stringa.substr(0, counter);
  107.  
  108. for (var i:Number = 0; i < len; i++){
  109. str = str + String.fromCharCode(Math.floor(Math.random()*(max - min)) + min);
  110. }
  111.  
  112. if (go < getTimer()){
  113. go = go + pausa;
  114. ++counter;
  115. --len;
  116. }
  117.  
  118. random_mc.random_txt.text = str;
  119. random_mc.random_txt.autoSize = true;
  120. random_mc.random_txt.embedFonts = this.embFonts;
  121. random_mc.random_txt.antiAliasType = this.antialias;
  122. random_mc.random_txt.selectable = false;
  123.  
  124. random_mc.random_txt.setTextFormat(format_fmt);
  125.  
  126. random_mc.random_txt._x = 0;
  127. random_mc.random_txt._y = 0;
  128.  
  129. if(len < 0){
  130. clearInterval(intervallo);
  131. }
  132. };
  133. intervallo = setInterval(setMatrixText, speed, _stringa);
  134. }
  135. }

Report this snippet  

You need to login to post a comment.