[Pixlib] Plugin architecture - plugin listening to model updates issue
Tim Will
thedigitalartist at gmail.com
Fri Jan 26 00:17:23 EST 2007
Seems like you found something I missed! :)
So do you think this:
o.apply( this, [e] );
means we can subscribe a function directly as a listener to a Broadcaster?
I haven't seen that done before so that would be kind of cool.
If so, wouldn't you have to subscribe that function directly - is that
possible in the plugins you describe?
Maybe its me missing something?
-tim.
On 1/25/07, Marcelo de Moraes Serpa <celoserpa at gmail.com> wrote:
>
> Hi Tim,
>
> Thanks for the reply ;)
>
>
> But again, I don't think there is a problem because if the
> > EventBroadcaster finds no handleEvent and no Method, it simply does nothing
> > to the class.
>
>
>
> Hmm.. I though that it would check if the listener object is a object or a
> movieclip. If so, it will either call handleEvent() or the method with the
> same name as the event type. Otherwise, if the object is a function, it will
> call this function on it's default context. Am I missing something here?
>
> Here's the code:
>
> private function _broadcast(aL:ListenerArray, e:IEvent) : Void
> {
> var l:Number = aL.length;
> while( --l > -1 )
> {
> var o = aL[l];
> var sType:String = typeof(o);
> if (sType == "object" || sType == "movieclip")
> {
> if (o.handleEvent != undefined)
> {
> o.handleEvent(e);
> } else
> {
> o[String(e.getType())](e);
> }
> } else //Se o objeto for uma função
> {
> o.apply( this, [e] );
> }
> }
> }
>
> Thanks!
>
>
>
> On 1/24/07, Tim Will < thedigitalartist at gmail.com> wrote:
> >
> > Well, I think it wouldn't be a problem Marcelo.
> > But if you did want to make a trap for all events the plugin is
> > listening to you could use a handleEvent() method. When the
> > EventBroadcaster broadcasts an event, the first thing it does is look for a
> > handleEvent() method in the listener - if it doesn't find it, it will call a
> > method of the same name as the event type. So you could use handleEvent()
> > to receive all events, then only call methods for the relevant ones....
> > But again, I don't think there is a problem because if the
> > EventBroadcaster finds no handleEvent and no Method, it simply does nothing
> > to the class.
> >
> > As a side-note, I'm loving plugins in pixioc!! Very excellent. Like
> > yourself, I'm doing a triditional pixlib project right now too, probably
> > rock the IOC on my next one.
> >
> > :)
> > -tim.
> >
> >
> > On 1/24/07, Marcelo de Moraes Serpa < celoserpa at gmail.com> wrote:
> >
> > > Hi guys!
> > >
> > > I know we are all excited and kind of busy playing and learning
> > > pixIoC. However, my current application isn't using it yet mainly because of
> > > deadline issues and also because I really didn't need the features pixIoC
> > > gracefully provide us.
> > >
> > > What I needed was on-demand loading of views. With the help of Stefan
> > > Vandermeulen (thanks Stefan!) which kindly made an working example of the
> > > first plugin system Francis suggested, I was able to start my next project
> > > using pixlib. However, I'm kind of stuck in the handling of events when it
> > > relates to the plugins.
> > >
> > > An important note: The plugins here are a mean to create
> > > "encapsulated" views, in other words, loadable graphical "forms" that get
> > > downloaded at runtime on user's request. It's by no means as flexible and
> > > abrangent as pixIoC plugins and is not an attempt to replace it :)
> > >
> > > A plugin is a subclass of PluginHelper which gets compiled along with
> > > a PluginUI (MovieClipHelper subclass) into a self-contained SWF that gets
> > > loaded by the shell swf using a subclass of GraphicLib (PluginLib). On the
> > > shell class (Application) I listen to the onLoadInitEVENT of the PluginLib
> > > event. It means that, when a plugin gets loaded, this method will get called
> > > and an instance of the PluginLibEvent will be passed to it.
> > >
> > > The PluginLibEvent has a method to get a reference to the PluginHelper
> > > instance. I put this instance into a variable of the type IPlugin (an
> > > interface that is already implemented by PluginHelper):
> > >
> > > var plugin:IPlugin = e.getTarget().getPlugin();
> > >
> > > //Register the plugin to listen for model updates
> > > ....
> > >
> > > Now, my doubt starts here, when I need to register the plugin to
> > > listen to the models of the application. Not all plugins will have methods
> > > to treat a specific model event type which will only be handled by
> > > interested plugins. If the registered listener object doesn't have a method
> > > to handle the event (either handleEvent or a method with the same name of
> > > the event), the broadcaster will call an undefined method on the object,
> > > right? Well, that's what bothers me. Could that be a problem? Should I make
> > > the plugins somehow tell the shell which models they "want" to listen for
> > > events? Or there's no problem on letting it the way it is now? (My concern
> > > is that it could affect perfomance somehow later).
> > >
> > > Thanks in advance,
> > >
> > > Marcelo.
> > >
> > > _______________________________________________
> > > Pixlib mailing list
> > > Pixlib at osflash.org
> > > http://osflash.org/mailman/listinfo/pixlib_osflash.org
> > >
> > >
> > >
> >
> > _______________________________________________
> > Pixlib mailing list
> > Pixlib at osflash.org
> > http://osflash.org/mailman/listinfo/pixlib_osflash.org
> >
> >
> >
>
> _______________________________________________
> Pixlib mailing list
> Pixlib at osflash.org
> http://osflash.org/mailman/listinfo/pixlib_osflash.org
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/pixlib_osflash.org/attachments/20070126/c6b19afc/attachment-0001.htm
More information about the Pixlib
mailing list