Показать сообщение отдельно
Старый 29.05.2014, 04:13
in4core вне форума Посмотреть профиль Отправить личное сообщение для in4core Найти все сообщения от in4core
  № 6  
Ответить с цитированием
in4core
 
Аватар для in4core

Регистрация: Mar 2009
Сообщений: 4,219
Записей в блоге: 14
На держи мое страье, даже приводить к норм не буду, но работать будет как часы

Код AS3:
package com.in4core.text 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author in4core
	 */
	public class Decoder extends EventDispatcher
	{
		private var _speed:uint;
		private var _str:String;
		private var _textfield:TextField;
		private var _rand:uint;
		private var _count:uint = 0;
		private var _index:uint = 1;
		private var _length:uint;
 
		private var _appendtext:String = '';
		private var _currentFormat:TextFormat = null;
		private var _fullFormat:TextFormat = null;
		private var _currentColor:int = -1;
		private var _tmp:TextField = new TextField();
 
		private var _interval:Timer = new Timer(20);
 
		public static const DEC_END:String = 'dec_end';
 
		public function open(text:String , tf:TextField , speed:uint = 20 , rand:uint = 0 , isStart:Boolean = false):void
		{
			_speed = speed;
 
			_textfield = tf;
 
			_str = text;
 
			_rand = rand;
 
			_length = _str.length;
 
			if (isStart) start();
		}
 
		public function start():void {
 
			_interval.reset();
 
			_textfield.text = '';
 
			addLetter();
 
			_interval.addEventListener(TimerEvent.TIMER , addLetter);
			_interval.start();
		}
 
		public function stop():void {
 
			_textfield.text = _appendtext;
 
			_interval.reset();
 
			_count = 0;
			_index = 1;
		}
 
		private function addLetter(e:TimerEvent = null):void {
 
			var a:String = String.fromCharCode(Math.floor(Math.random() * 93 + 33)).toLowerCase(); // Latin and punctuation
			//var b:String = String.fromCharCode(Math.floor(Math.random() * 63 + 1040)).toLowerCase(); // cyrillic
			//var c:String = String.fromCharCode(Math.floor(Math.random() * 31 + 33)).toLowerCase(); // punctuation
 
			var tempStr:String = a;
 
			if (_count < _rand) _count ++ ;
 
			else 
			{
				_count = 1;
				_appendtext = _str.slice(0, _index);
				_index ++;
			}
 
			if ( _rand ) 
			{
				_textfield.text = _appendtext + tempStr;
			}
 
			else _textfield.text =  _appendtext;
 
 
			if (_index == _length + 1) 
			{
				stop();
				this.dispatchEvent(new Event(Decoder.DEC_END) );
				destroy();
			}
		}
 
		public function destroy():void
		{
			_interval.removeEventListener(TimerEvent.TIMER , addLetter);
		}
	}
}
__________________
Марк Tween