Loading
  Password:
  Lost password?  
LogoutLOGOUT
Join as a MemberJoin as a Member
 
FlashMove Live Support



Go Back   FlashMove Forums > Development > Archives > Flash MX 2004

ReplyREPLY THREAD
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-09-2003, 03:56 PM
dv8's Avatar
dv8 dv8 is offline

Admin Mod
 
Join Date: Mar 2001
Posts: 2,053
dv8 is on a distinguished road
EventDispatcher

Peter Joel Hall of http://www.peterjoel.com talks about in his blog the replacement for AsBroadcaster, the supported EventDispatcher.

So I did some digging...

EventDispatcher works the same way as AsBroadcaster, but more powerful. Enabling the developer to return the Event type and Event target.

Example of EventDispatcher Class -
Actionscript:
/*
Timer Class
 - This is one of my favorites. It's not mine by origin, but I redid it for AS2.0
*/
// Import event class
import mx.events.EventDispatcher;
class com.flashmove.Timer {
	// declare properties and methods
	var _timeout:Number;
	var intervalid:Number;
	var dispatchEvent:Function;
	var addEventListener:Function;
	var removeEventListener:Function;
	//Timer Constructor
	function Timer() {
		// tell EventDispatcher to allow inheritance to Timer
		EventDispatcher.initialize(this);
	}
	//public methods
	public function toString() {
		return "[object Timer]";
	}
	public function start(timeout:Number) {
		//when does this timer, fire?
		_timeout = timeout;
		//start the timer
		reset();
	}
	public function stop() {
		//get rid of the interval
		clearInterval(intervalid);
	}
	public function reset() {
		stop();
		//set a new interval
		intervalid = setInterval(this, "fire", _timeout);
	}
	//private method
	private function fire() {
		//tell all the listeners that this timer has runout
		dispatchEvent({type:"onTimeOut"});
	}
}
Actionscript:
//Usage -
import com.flashmove.Timer;

var timer_obj:Timer = new Timer();
var listener:Object = {};
listener.onTimeOut = function () {
	trace(e.type + " was broadcast by " + e.target); //output: onTimeOut was broadcast by [object Timer]
}
timer_obj.addEventListener("onTimeOut", listener);
timer_obj.start(1000);

I'm still learning more, but I thought I'd share with my progress.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT. The time now is 08:14 PM.




Powered by vBulletin version 3.5