el codigo lo copie de aca: http://www.cristalab.com/tutoriales/clase-para-crear-texto-en-forma-aleatoria-con-actionscript-3-c63360l/
Bueno en el primer fotograma del .fla tengo este codigo:
Código ActionScript :
package ph.display.text{
//
import flash.text.TextField;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
//
public class TextHolder extends TextField {
//
private var field:TextField;
private var txt:String;
private var currrentString:String;
private var chars:String;
private var charsArray:Array;
private var timer:Timer;
private var txtLength:uint;
private var counter:uint;
private var speed:uint;
private var incress:uint;
private var ignoreW:Boolean;
//
//public function TextHolder():void {}; // como el costructor está vacio no es imprescindible
//
public function createRandomText(_txt:String, _speed:uint = 20, _incress:uint = 1, ignoreWhite:Boolean = false):void {
//
txt = _txt;
speed = _speed;
incress = _incress;
ignoreW = ignoreWhite;
//
field = this;
txtLength = txt.length;
counter = 0;
//
var chars:String = "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 ! @ # $ % ^ & * ( ) { } < > / ?";
charsArray = chars.split(" ");
currrentString = new String();
//
doTimer();
}
//
private function doTimer():void {
//
timer = new Timer(speed, txtLength);
timer.addEventListener(TimerEvent.TIMER, incressment);
timer.start();
}
//
private function incressment(e:Event = null):void {
//
currrentString += txt.substr(counter, incress);
counter += incress;
field.text = (currrentString + rand(txtLength - counter));
}
//
private function rand(t:uint):String {
//
var randomText:String = "";
//
for (var i:int = 0; i < t; i++) {
//
if (!ignoreW && txt.charAt(counter + i) == " ") {
randomText += " ";
} else {
randomText += charsArray[uint(Math.random() * charsArray.length)];
}
}
return randomText;
}
//
}// class
}// package
y en el archivo as tengo este otro:
Código ActionScript :
package {
//
import flash.display.MovieClip;
import flash.text.TextFieldAutoSize;
import ph.display.text.TextHolder;
//
public class Main extends MovieClip {
//
private var randTxt:TextHolder;
private var txtString:String;
//
public function Main() {
//
buildText();
}
//
private function buildText():void {
//
txtString = "Lorem ipsum dolor sit amet.";
//
randTxt = new TextHolder();
randTxt.createRandomText(txtString);
randTxt.autoSize = TextFieldAutoSize.LEFT;
//
addChild(randTxt);
}
//
}// class
}// package
en el archivo fla, en propiedades coloque en clase: Main
al probar mi archivo me sale: error 1037 los paquetes no se pueden anidar, estoy usando flash cs6 y publicacion as3 y flash 11.2.
espero haberme explicado bien y espero su ayuda, de verdad gracias.
