Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Пауза между таймерами (http://www.flasher.ru/forum/showthread.php?t=166320)

Isaac 01.09.2011 21:58

Пауза между таймерами
 
Есть ф-ии
Код AS3:

public function effText():void
                {
                        frameTime = Math.round(textSpeed * 1 / this.stage.frameRate);
                        charTimer = new Timer(frameTime);
 
                        charTimer.addEventListener(TimerEvent.TIMER, charTimerComplete);
                        charTimer.start();
 
                        charTimerTarget = txt1;
                        charTimerTargetSource = 'Bad decisions\ncatching up with you?';
                        charTimerTargetData = charTimerTargetSource.split('');
                        charTimerTargetCount = 0;
                }
 
                public function charTimerComplete(event:TimerEvent):void
                {
                        if (charTimerTargetCount < charTimerTargetData.length)
                        {
                                charTimerTarget.appendText(charTimerTargetData[charTimerTargetCount]);
                                charTimerTargetCount ++;
                        }else
                        {
                                switch(messageCount)
                                {
                                        case 0:
                                        {
                                                txt1.text = '';                                                                                               
                                                charTimerTargetSource = 'Improve your driving skills\nwith traffic school... Online!';                                               
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 1:
                                        {
                                                txt1.text = '';
 
                                                charTimerTargetSource = 'Clear your record at\nyour own convenience.';
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 2:
                                        {
                                                txt1.text = '';
                                                txt1.y = 15;
                                                charTimerTargetSource = "Start your court-approved\ntraffic school\nbefore it's too late!";
                                                charTimerTargetData = charTimerTargetSource.split('
');
                                                charTimerTargetCount = 0;
                                        } break;
 
                                        case 3:
                                        {
                                                charTimer.stop();
                                        } break;
                                }
 
                                messageCount ++;
                        }                       
                }

Как сделать, чтоб после каждого case, перед выводом нового сообщения и перед charTimerTargetCount = 0;(очисткой строки), была небольшая пауза ?

КорДум 01.09.2011 21:59

Разбить на две функции, вторую вызывать по таймеру.

Newred 01.09.2011 22:32

забирай)

Код AS3:

public function effText():void
                {
                        frameTime = Math.round(textSpeed * 1 / this.stage.frameRate);
                        charTimer = new Timer(frameTime);
 
                        charTimer.addEventListener(TimerEvent.TIMER, charTimerComplete);
                        charTimer.start();
 
                        charTimerTarget = txt1;
                        charTimerTargetSource = 'Bad decisions\ncatching up with you?';
                        charTimerTargetData = charTimerTargetSource.split('');
                        charTimerTargetCount = 0;
                }
 
 
                private function latensy():void
                {
                        var latensyTimer = new Timer(1500,1); //задержка 1,5 секунды
 
                        latensyTimer.addEventListener(TimerEvent.TIMER, latensyTimerComplete);
                        latensyTimer.start();
                }
 
                private function latensyTimerComplete(e:TimerEvent):void
                {
                        switch(messageCount)
                                {
                                        case 0:
                                        {
                                                txt1.text = '';                                                                                               
                                                charTimerTargetSource = 'Improve your driving skills\nwith traffic school... Online!';                                               
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 1:
                                        {
                                                txt1.text = '';
 
                                                charTimerTargetSource = 'Clear your record at\nyour own convenience.';
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 2:
                                        {
                                                txt1.text = '';
                                                txt1.y = 15;
                                                charTimerTargetSource = "Start your court-approved\ntraffic school\nbefore it s too late!";
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;
                                        } break;
 
                                        case 3:
                                        {
                                                charTimer.stop();
                                        } break;
                                }
 
                                messageCount ++;
                }
 
                public function charTimerComplete(event:TimerEvent):void
                {
                        if (charTimerTargetCount < charTimerTargetData.length)
                        {
                                charTimerTarget.appendText(charTimerTargetData[charTimerTargetCount]);
                                charTimerTargetCount ++;
                        }else
                        {
                        switch(messageCount)
                                {
                                        case 0:
                                        {
// то что нужно выполнить сразу перенеси сюда из latensyTimerComplete                                       
                                        } break;
 
                                        case 1:
                                        {
 
                                        } break;
 
                                        case 2:
                                        {
 
                                        } break;
 
                                        case 3:
                                        {
 
                                        } break;
                                }
                                latensy();
                        }
}


Isaac 01.09.2011 23:43

Цитата:

Сообщение от Newred (Сообщение 1027525)
забирай)

Код AS3:

public function effText():void
                {
                        frameTime = Math.round(textSpeed * 1 / this.stage.frameRate);
                        charTimer = new Timer(frameTime);
 
                        charTimer.addEventListener(TimerEvent.TIMER, charTimerComplete);
                        charTimer.start();
 
                        charTimerTarget = txt1;
                        charTimerTargetSource = 'Bad decisions\ncatching up with you?';
                        charTimerTargetData = charTimerTargetSource.split('');
                        charTimerTargetCount = 0;
                }
 
 
                private function latensy():void
                {
                        var latensyTimer = new Timer(1500,1); //задержка 1,5 секунды
 
                        latensyTimer.addEventListener(TimerEvent.TIMER, latensyTimerComplete);
                        latensyTimer.start();
                }
 
                private function latensyTimerComplete(e:TimerEvent):void
                {
                        switch(messageCount)
                                {
                                        case 0:
                                        {
                                                txt1.text = '';                                                                                               
                                                charTimerTargetSource = 'Improve your driving skills\nwith traffic school... Online!';                                               
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 1:
                                        {
                                                txt1.text = '';
 
                                                charTimerTargetSource = 'Clear your record at\nyour own convenience.';
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 2:
                                        {
                                                txt1.text = '';
                                                txt1.y = 15;
                                                charTimerTargetSource = "Start your court-approved\ntraffic school\nbefore it s too late!";
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;
                                        } break;
 
                                        case 3:
                                        {
                                                charTimer.stop();
                                        } break;
                                }
 
                                messageCount ++;
                }
 
                public function charTimerComplete(event:TimerEvent):void
                {
                        if (charTimerTargetCount < charTimerTargetData.length)
                        {
                                charTimerTarget.appendText(charTimerTargetData[charTimerTargetCount]);
                                charTimerTargetCount ++;
                        }else
                        {
                        switch(messageCount)
                                {
                                        case 0:
                                        {
// то что нужно выполнить сразу перенеси сюда из latensyTimerComplete                                       
                                        } break;
 
                                        case 1:
                                        {
 
                                        } break;
 
                                        case 2:
                                        {
 
                                        } break;
 
                                        case 3:
                                        {
 
                                        } break;
                                }
                                latensy();
                        }


Все сделал, как вы и написали, а флеш выдает ошибку :(
Код AS3:

C:\Users\Armen\Desktop\b\Main.as, Line 344        1013: The private attribute may be used only on class property definitions.

Добавлено через 9 минут
Цитата:

Сообщение от Newred (Сообщение 1027525)
забирай)

Вы имели в виду так?
Код AS3:

private function effText():void
                {
                        frameTime = Math.round(textSpeed * 1 / this.stage.frameRate);
                        charTimer = new Timer(frameTime);
 
                        charTimer.addEventListener(TimerEvent.TIMER, charTimerComplete);
                        charTimer.start();
 
                        charTimerTarget = txt1;
                        charTimerTargetSource = 'Bad decisions\ncatching up with you?';
                        charTimerTargetData = charTimerTargetSource.split('');
                        charTimerTargetCount = 0;
                }
 
                private function latensy():void
                {
                        var latensyTimer = new Timer(1500,1); //задержка 1,5 секунды
 
                        latensyTimer.addEventListener(TimerEvent.TIMER, latensyTimerComplete);
                        latensyTimer.start();
                }
 
                private function latensyTimerComplete(event:TimerEvent):void
                {
                        switch(messageCount)
                                {
                                        case 0:
                                        {
                                                txt1.text = '';                                                                                               
                                                charTimerTargetSource = 'Improve your driving skills\nwith traffic school... Online!';                                               
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 1:
                                        {
                                                txt1.text = '';
                                                charTimerTargetSource = 'Clear your record at\nyour own convenience.';
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        } break;
 
                                        case 2:
                                        {
                                                txt1.text = '';
                                                txt1.y = 15;
                                                charTimerTargetSource = "Start your court-approved\ntraffic school\nbefore it s too late!";
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;
                                        } break;
 
                                        case 3:
                                        {
                                                charTimer.stop();
                                        } break;
                                }
 
                                messageCount ++;
                }
 
                private function charTimerComplete(event:TimerEvent):void
                {
                        if (charTimerTargetCount < charTimerTargetData.length)
                        {
                                charTimerTarget.appendText(charTimerTargetData[charTimerTargetCount]);
                                charTimerTargetCount ++;
                        }else
                        {
                                switch(messageCount)
                                {
                                        case 0:
                                        {
                                                txt1.text = '';                                                                                               
                                                charTimerTargetSource = 'Improve your driving skills\nwith traffic school... Online!';                                               
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;       
                                        }break;
 
                                        case 1:
                                        {
                                                txt1.text = '';
                                                charTimerTargetSource = 'Clear your record at\nyour own convenience.';
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        }break;
 
                                        case 2:
                                        {
                                                txt1.text = '';
                                                txt1.y = 15;
                                                charTimerTargetSource = "Start your court-approved\ntraffic school\nbefore it s too late!";
                                                charTimerTargetData = charTimerTargetSource.split('');
                                                charTimerTargetCount = 0;                                               
                                        }break;
 
                                        case  3:
                                        {
                                                charTimer.stop();
                                        }break;
                                }
 
                                latensy();
                        }
                }

Ошибок сейчас нет, но получается какая-то ерунда :(

Newred 02.09.2011 03:55

В моём примере была пропущена скобка в конце функции, исправил.

Что выводит строка
Код AS3:

 trace("frameTime "+frameTime);


Isaac 02.09.2011 13:34

Цитата:

Сообщение от Newred (Сообщение 1027591)
В моём примере была пропущена скобка в конце функции, исправил.

Что выводит строка
Код AS3:

 trace("frameTime "+frameTime);


Вот что выводит
Код AS3:

frameTime 21
frameTime 21
frameTime 21
frameTime 21

Я так понял, что идет наложение текста один на другой :(

Newred 04.09.2011 04:56

1 секунда = 1000 мс
В данном случае функция
Код AS3:

charTimerComplete

выполняется примерно 50 раз в секунду(1000/21)
если в коде поменять
frameTime = Math.round(textSpeed * 1 / this.stage.frameRate); на
frameTime = 1000; // будет задержка в 1 секунду.

ps можете мне в личку скинуть исходники, поправлю.


Часовой пояс GMT +4, время: 21:54.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2024, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.