[xinf] Events (was: Re: info for potential new developers)

hank williams hank777 at gmail.com
Tue Jun 13 03:21:54 CEST 2006


I am not quite sure I understand what you are saying about events, but
it *sounds* similar to the way I do events. Unless I have to I dont
use flash events because they cause highly unfactored interdependent
code.

I have a class which I call messageWire, which has been the anchor of
all the event stuff I do. It is generally a global, but it doesnt have
to be. And what you do is when you want to generate an event, you
generate the event by calling a "broadcast" method of the messageWire
class with a string and a object that contains the relevant data for
the event. The string name is the event. Then if another part of the
code is interested in that event, it registers its interest in that
type of event along with the object and function to call when that
event is received.

This avoids the need for any object to ever need to have access to any
other object in order to receive messages from that object. This means
that you can drop in a new piece of code into a project and if it
generates and/or understands certain events it can work without any
modification at all. Now the down side to this is you do have to
document the semantics of you messaging very clearly up front, or you
may have no idea what the effect of sending a message may be to
recipients that you had forgotten about. But I have written tools that
let me easily see where all the messages are going. With haxe it might
be possibible to add some type checking goodness to this instead of
having stuff be purely string based with an anonymou object as it is
now.

It works really well for me, and one of the cool things is that these
messages can be passed between the C world and the VM world
seamlessly. (this isnt done yet but it will be). This allows me to
register C code that should get called when an event is triggered
inside haxe code. For what I am doing, this makes for pure
architectural bliss.

Regards,
Hank

On 6/12/06, daniel fischer <dan at f3c.com> wrote:
> Hey Rostislav-
>
> "Rostislav Siryk" <Siryk at validio.com.ua> (on Fri, 9 Jun 2006 21:47:28 +0300):
>
>   > At this moment I have not very much time to dive into this project but
>   > one thing I can remember just right is now often flash developers
>   > complained of poor realization of delegating events in AS2 API. One of
>
> can you bring up valid uses for event delegation, except working around the b0rked flash event handling? i'd prefer delegation to "not be neccessary".
>
> In fact, the whole Event system in xinf is (as the rest) rather ad-hoc. I'd really like some eyes on it. Just today i've discussed a little with Mark, and as a consequence threw out the stopPropagation function, as i don't want to keep features for which i once had some weak rationale but dont have any more.
>
> The idea is that there are global events (like enterFrame) which you can handle by registering with org.xinf.event.EventDispatcher.addGlobalEventListener(), and local ones which "happen" on ony.Elements. Local events will (and do- see dispatchEvent in org.xinf.ony.Element) bubble up the display hierarchy. The individual runtime implementations should assure that this system works consistently- although i have a real problem with flash's way of sending eg onPress events first, and only, to the parent if it has registered it- i need a way to work around this consistently, which i haven't come up with yet (although- i've just encountered the problem today- you can see i'm not a flash programmer :). Any ideas here would be appreciated.
>
> Nicolas just suggested an interesting method to make Events somewhat more type-safe (thread "EventDispatcher" on the haXe list- the archives seem down so sorry no link), which i haven't thought about enough. Maybe you (all) have ideas, too?
>
> Another question, eg, is if the current way in xinf (eventListeners are registered in an array in a hash by type) is good- i.e., is it really neccessary to be able to register more than one handler for an event type? For enterFrame, and likely other global events, sure, but for Element events? It's currently a little awkward to unregister events- as haXe automatically generates wrapper functions if you pass on functions, using "onMouseDown" in the same class to register and trying to unregister wont work- "(this.)onMouseDown" gives two different wrapper functions for each time it's used, so removeEventListener cannot find the handler function in the Array to remove it. Maybe an EventListener signature will work around this?
>
> The data part in Events is somewhat shaky too- maybe subclasses a la MouseEvent/KeyboardEvent would be better?
>
> Anyhow, all please have a look at
>   http://xinf.org/trac/browser/trunk/org/xinf/event/
> and maybe org/xinf/ony/Element.hx, and scan for insanity or better options- suggestions appreciated.
>
>
>   > Good Luck with cool initiative of XINF!
>
> thanks alot. good luck with whatever you do ;)
>
> -dan
>
> --
> http://0xDF.com/
> http://iterative.org/
>
> --
> xinf is not flash
> http://xinf.org/
>


More information about the xinf mailing list