|
|
|||||
Регистрация: Jan 2012
Сообщений: 836
|
Эффект печатающего текста
Кто может дать пример? Как тут
http://edapskov.ru/pages.php?id=13 только на as3, буду очень благодарен) |
|
|||||
Регистрация: Nov 2013
Сообщений: 86
|
Почитайте комментарии, там дан.
|
|
|||||
Регистрация: Jan 2012
Сообщений: 836
|
Сделал как в том примере
private function text_function():void { var intervalID:int = setInterval(text_function, interval); var count:int = 0; var interval:int = 100; var str:String = 'Ловкий сокол - не праведник и не святоша. Мечут в сердце греховные стрелы ресницы!'; if (count<=str.length) { text_dialog.txt_dialog.text = str.substr(0, count); text_dialog.txt_dialog.text += str.substr(count, 1)+'|'; count++; } else { clearInterval(intervalID); text_dialog.txt_dialog.text = str.substr(0, count); } } } } |
|
|||||
Попробуйте вынести count за функцию. Убрать clearInterval и поменять setInterval на setTimeout.
И interval вынести за пределы функции тоже.
__________________
There is no thing in this world that is not simple. |
|
|||||
[+4 06.05.14]
|
На держи мое страье, даже приводить к норм не буду, но работать будет как часы
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 |
|
|||||
Регистрация: Jan 2012
Сообщений: 836
|
Спасибо большое. Все заработало
|
Часовой пояс GMT +4, время: 22:33. |
|
« Предыдущая тема | Следующая тема » |
|
|