Форум Flasher.ru
Ближайшие курсы в Школе RealTime
Список интенсивных курсов: [см.]  
  
Специальные предложения: [см.]  
  
 
Блоги Правила Справка Пользователи Календарь Поиск рулит! Сообщения за день Все разделы прочитаны
 

Вернуться   Форум Flasher.ru > Flash > ActionScript 1.0/2.0

Версия для печати  Отправить по электронной почте    « Предыдущая тема | Следующая тема »  
Опции темы Опции просмотра
 
Создать новую тему  
Старый 13.10.2008, 14:28
zanull вне форума Посмотреть профиль Отправить личное сообщение для zanull Найти все сообщения от zanull
  № 3  
Ответить с цитированием
zanull

Регистрация: Jan 2008
Адрес: flex.org
Сообщений: 211
пример таймера с запуском и остановкой:

Код:
Timer = function(start){
	this.reset(start);
}
Timer.prototype.start = function(){
	if (this._pauseTime){
		this._startTime += getTimer() - this._pauseTime;
		this._pauseTime = 0;
	}else{
		this.reset(true);
	}
}
Timer.prototype.stop = function(){
	if (!this._pauseTime) this._pauseTime = getTimer();
}
Timer.prototype.reset = function(restart){
	this._startTime = getTimer();
	if (!this._startTime) this._startTime = 1;
	if (restart) this._pauseTime = 0;
	else this._pauseTime = this._startTime;
}

Timer.prototype.getTime = function(){
	if (this._pauseTime) return this._pauseTime - this._startTime;
	var gotTime = getTimer();
	if (!gotTime) gotTime = 1;
	return gotTime - this._startTime;
}
Timer.prototype.setTime = function(t){
	this._startTime = getTimer() - t;
}
Timer.prototype.addProperty("time",Timer.prototype.getTime,Timer.prototype.setTime);

Timer.prototype.getPaused = function(){
	return (this._pauseTime) ? true : false;
}
Timer.prototype.setPaused = function(p){
	if (p == Boolean(this._pauseTime)) return false;
	if (p) this.stop();
	else this.start();
}
Timer.prototype.addProperty("paused",Timer.prototype.getPaused,Timer.prototype.setPaused);

function formatTime(milliseconds){
	var centiseconds = Math.floor(milliseconds/10);
	var seconds = Math.floor(centiseconds/100);
	var minutes = Math.floor(seconds/60);
	
	centiseconds %= 0;
	seconds %= 60;
	minutes %= 60;
	
	if (centiseconds < 10) centiseconds = "0" + centiseconds;
	if (seconds < 10) seconds = "0" + seconds;
	if (minutes < 10) minutes = "0" + minutes;
	
	return minutes +":"+ seconds +""+ centiseconds;
}


var clock_timer = new Timer();
clock_timer.start();


this.onEnterFrame = function(){
	display_txt.text = formatTime(clock_timer.time);
}

stop_btn.onRelease = function(){
	clock_timer.stop();
}

play_btn.onRelease = function(){
	if (clock_timer.paused) clock_timer.start(); // only start if paused
}
display_txt - имя текстового поля
__________________
Синие теннисные мячики никогда не уронят своей чести...

Создать новую тему   Часовой пояс GMT +4, время: 10:05.
Быстрый переход
  « Предыдущая тема | Следующая тема »  
Опции темы
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.


 


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


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