Thanks everyone for the detailed explanations and pointers to the relevant
areas in dynapi.js, etc.
Makes more sense to me.
Cheers,
James
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
--- Begin Message ---
At 2002-07-12 00:17, James Musick wrote:
I think the problem is that I
didn't/don't understand when things are being called and/or triggered by
DynAPI.
For example:
File A:
anObj= new myObject();
.....other stuff
DynAPI.document.addChild(anObj);
---------
File B:
function myObject()
{
this.field1=null;this.field2=null;
var l = new EventListener(this);
l.oncreate = function(e)
{var o = e.getTarget();}
}
[snip]
So the way I'm currently
thinking of it (and this may *still* be confused...so please correct
me/add to the info if possible) is that the above code will
1. Create an instance of myObject called anObj.
Yes. But as written above its superclass is the generic Object in
javascript, not a DynObject.
2. Part of this object is an
EventListener
The object has an empty array of EventListeners as a property
(dynapi.js)
3. somehow/somewhere the
oncreate() function of the event listener is called inside of
DynAPI.document.addChild()
The addChild method in dyndocument.js calls the addChild method in
dynapi.js for the DynObject.
DynObject.prototype.addChild = function(c) {
if(c.isChild)
c.parent.removeChild(c);
c.isChild
= true;
c.parent =
this;
if(this.created)
c.create() //
<- Step one
this.children[this.children.length]
= c;
return
c;
};
DynObject.prototype.create = function() {
this.flagPrecreate();
this.specificCreate();
this.created
= true;
var l =
this.children.length;
for(var
i=0;i<l;i++) this.children[i].create()
this.invokeEvent("create"); //
<- This is the one you're looking for
};
4. That call of
oncreate is passing a reference of the event 'e' that triggered the
'oncreate' call.
DynObject.prototype.invokeEvent=function(type,e,args)
{
if (!e)
e=new DynEvent(type,this);
if
(this.hasEventListeners) for(var i=0;i<this.eventListeners.length;i++)
{
e.target=this.eventListeners[i].target;
this.eventListeners[i].handleEvent(type,e,args);
}
...
}
EventListener.prototype.handleEvent=function(type,e,args)
{
if(this["on"+type])
this["on"+type](e,args);
};
As the call to invokeEvent didn't provide the e argument a new
DynEvent is created, with the current object as its source.
5. e.getTarget() returns the
object that triggered it all in the beginning.
In effect yes, but getTarget simply returns the "target"
property of the event. It gets a little messier if the event bubbles...
or quite powerful if you set up the listener in a different
way.
You could for example have a list where the listener for the items in the
list has the list they will be attached to as their target.
To complicate matters: there is a getSource method too... That one should
be the one that triggered it.
3,4,5 are still pretty
speculative since I didn't see code doing that specifically.
But the addChild() must be triggering the oncreate event somehow,
but I'm not sure how/why.
You could have multiple Event listeners with a single object,
certainly. If you did an addChild() I guess it seems that an event is
firing (perhaps of a type that is a creation event) and so all the
EventListeners that are associated with the object (only 'l' in this
case) execute their oncreate function.
I think what was confusing me was that when you create an instance
of the object you're not really triggering the oncreate() function. That
seems to happen when you do Dynapi.document.addChild().
Is this roughly correct?
Roughly. The oncreate is called after the browser element has been
created (a "div" most often). If you are addChild()ing to an
object that hasn't been created yet the oncreate() isn't called at that
time. It will be called when the parent becomes part of the document
though.
Please note that DynAPI.document isn't the standard "document"
object but a DynDocument.
Thanks, by the way, for the
discussion/help.
Cheers,
James
You're welcome!
/Lunna
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
PC Mods, Computing goodies, cases & more
http://thinkgeek.com/sf
_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dynapi-help
--- End Message ---