SIGINT
12-24-2002, 01:44 PM
Hi everybody,
i got this Problem:
I want to define a Object in Javascript and "attach" an Event to it. This Event shall fire a method of the object.
I tried this:
function layer_pos(x,y)
{
this.obj.style.left=x;
this.obj.style.top=y;
}
function layer(name,x,y,w,h)
{
obj = document.createElement("div");
obj.style.position="absolute";
obj.style.background="#ffff00";
obj.style.left=x;
obj.style.top=y;
obj.style.width=w;
obj.style.height=h;
obj.id=name;
document.body.appendChild(obj);
this.obj=obj;
this.pos=layer_pos;
this.hand=hand;
}
function hand(x,y)
{
this.obj.style.left=x;
}
Then i can create an instance of layer:
test=new layer("test",10,10,100,100);
I can write a Eventhandler,which handels all mouseevents and calls hand(event.x,event.y).
But this code is bull****,because i dont's know how to get the object,which shound recieve the event,i only know the target( == test.obj).
I want the object test as event.target but i get test.obj :-((
Does anyone know ,how i can include a eventhandler into the object-description?
Thx SIGINT
i got this Problem:
I want to define a Object in Javascript and "attach" an Event to it. This Event shall fire a method of the object.
I tried this:
function layer_pos(x,y)
{
this.obj.style.left=x;
this.obj.style.top=y;
}
function layer(name,x,y,w,h)
{
obj = document.createElement("div");
obj.style.position="absolute";
obj.style.background="#ffff00";
obj.style.left=x;
obj.style.top=y;
obj.style.width=w;
obj.style.height=h;
obj.id=name;
document.body.appendChild(obj);
this.obj=obj;
this.pos=layer_pos;
this.hand=hand;
}
function hand(x,y)
{
this.obj.style.left=x;
}
Then i can create an instance of layer:
test=new layer("test",10,10,100,100);
I can write a Eventhandler,which handels all mouseevents and calls hand(event.x,event.y).
But this code is bull****,because i dont's know how to get the object,which shound recieve the event,i only know the target( == test.obj).
I want the object test as event.target but i get test.obj :-((
Does anyone know ,how i can include a eventhandler into the object-description?
Thx SIGINT