Показать сообщение отдельно
Старый 18.01.2008, 15:16
$mival вне форума Посмотреть профиль Отправить личное сообщение для $mival Найти все сообщения от $mival
  № 1  
Ответить с цитированием
$mival
 
Аватар для $mival

Регистрация: Oct 2005
Адрес: Russia, Irkutsk
Сообщений: 742
По умолчанию Подписаться на событие не зная класса, генерирующего событие

Сабж. Возможно ли такое? В книге Мука такой пример:

Console class
Код:
// The Console class (registers a listener for the event)
package {
	
	import flash.display.*;
	import flash.events.*;
	
	public class Console extends Sprite {
	
		// Constructor
		public function Console () {
			var game:Game = new Game();
			game.addEventListener(Game.GAME_OVER, gameOverListener);
		}
		
		private function gameOverListener (e:Event):void {
			trace("The game has ended!");
			// Display "back to console" UI (code not shown)
		}
	}
}
Game class
Код:
// The Game class (the event target)
package {
	
	import flash.events.*;
	import flash.utils.*; // Required for the Timer class
	
	public class Game extends EventDispatcher {
		
		public static const GAME_OVER:String = "gameOver";
		
		public function Game () {
			// Force the game to end after one second
			var timer:Timer = new Timer(1000, 1);
			timer.addEventListener(TimerEvent.TIMER, timerListener);
			timer.start();
			// A nested function that is executed one second after this object
			// is created
			function timerListener (e:TimerEvent):void {
				endGame();
			}
		}
		private function endGame ():void {
			// Perform game-ending duties (code not shown)...
			// ...then ask ActionScript to dispatch an event indicating that
			// the game is over
			dispatchEvent(new Event(Game.GAME_OVER));
		}
	}
}
тут в Console мы создаем экземпляр Game и только после этого подписываемся. А как подписаться без ссылки на класс?
Спасибо.
__________________
smival.com