Heya Robin,

Is that a custom ver of the MX in-built EventDispatcher or just a derived version of it? - just curious as i'm yet to touch base on the i2 stuff.

Scott


Robin Hilliard wrote:

[EMAIL PROTECTED] wrote:

Hey Robin


Even firing off events in child movieclips, let alone
textfields is doing my head in. I just cant seem to find any documentation
on how to manage events in movieclips inside movieclips inside movieclips
etc etc.


In the iteration::two Flex framework (just as applicable to Flash) which we're currently using on a Flex project, they use a singleton EventBroadcaster class:


class com.ourclient.theirapp.control.EventBroadcaster {
public var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;
private static var eventBroadcaster;
public static function getInstance() {
if (eventBroadcaster == undefined)
eventBroadcaster = new EventBroadcaster();
return eventBroadcaster;
}
private function EventBroadcaster() {
EventDispatcher.initialize(this);
}
public function broadcastEvent(eventName:String,
eventData:Object, eventSource:Object) {
var event:Event = new Event();
event.type = eventName;
event.data = eventData;
event.source = eventSource;
dispatchEvent(event);
}
}


No matter how deeply nested you get in your views (MovieClips), wherever you are you can dispatch a global event like this:

EventBroadcaster.getInstance().broadcastEvent("someEvent", data, this);

Data and source are optional. Doing it this way means all your movie clips don't get tied up working out which events to handle, pass on etc - they only need to be concerned with displaying data.

Responding to user input is the job of the controller. Get your controller class to listen to the event broadcaster, look at the event type and do it's thing. In the iteration::two framework they delegate the handling of each event out to a custom "command" class (handy if you're calling more than one server method and want distinct onResult handlers), but you can just have a big switch statement to start with. When you need to display data, set variables in your root movie clip and pass them out to the views - in Flex you use binding but in Flash you could use implicit setters to pass data out to the views, e.g:

root:

public function set peopleList(p:Array):Void {
    tabA.peopleList = p;
    tabB.peopleList = p;
}

in the class tabA is an instance of:

public var peopleList:Array;

or

public function set peopleList(p:Array):Void {

    // pass on to more sub-views or do whatever is necessary
    // to refresh view

}

As long as the views rely on others setting their public properties to get data and the EventBroadcaster to send events, they have absolutely no idea where they're being used in your UI, which makes them nice and portable/reusable.

One last thing - use value objects to pass your data around - the peopleList array might be an array of objects like this:

class com.ourclient.theirapp.vo.PersonVO {
    var firstName:String;
    var surname:String;
    ...
}

If you pass around VOs you're free to add or change properties without having to update all those setters in your view code.

Happy to answer more questions if you or others are interested.

Cheers,
Robin

http://www.rocketboots.com.au



--- You are currently subscribed to fugli as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to