object orjented problem

Discussion in 'JavaScript' started by patuljak, Sep 28, 2007.

  1. #1
    hi!

    I'm trying to create class with all necesery methods for slide bar graphic element.
    the problem is whenever i create new instance of that class i lose all event listeners for other instances of the same class...
    Actualy all i know is that only last instance is event sensitive.
    here is the script... it should only alert a message when mouse button is presed in the slider area .

    any ideas?

    thx!

    btw sorry for my bed english



    doc=document;
    function sliderbar(parentdocid,pozx,pozy,maxvalue,size,slidername)
    {
    var poz=0;

    this.slidersize=size/25;
    this.htmlcod=slidername;
    this.htmlcod+="<div id=\""+slidername+"\" style=\"border: black thin solid; position:relative; left:"+pozx+"px; top:"+pozy+"px; width:"+size+"px; height:20px;\" onmouseover=\"javascript:mover(event);\">";
    this.htmlcod+="<div id="+slidername+"slide style=\" position:absolut; background-color:grey; width:"+this.slidersize+"px; height:20px;\"></div></div>";

    this.parent=doc.getElementById(parentdocid);
    this.parent.innerHTML+=this.htmlcod;
    this.sliderbar=doc.getElementById(slidername);
    this.slider=doc.getElementById(slidername+"slide");

    while(this.slider.offsetParent)
    {
    this.poz += this.slider.offsetLeft;
    this.slider=this.slider.offsetParent;
    }
    this.slider=doc.getElementById(slidername+"slide");
    this.grab=function()
    {
    alert(poz);
    }
    this.move=function()
    {
    }
    this.drop=function()
    {
    }
    this.sliderbar.addEventListener("mousedown",this.grab,true);
    return;
    }
    var slider1=new sliderbar("formsettings",55,-20,255,150,"RED");
    var slider2=new sliderbar("formsettings",55,-20,255,150,"GREEN");
    var slider3=new sliderbar("formsettings",55,-20,255,150,"BLUE");

    html part
    <div id="formsettings" class="settings"></div>
     
    patuljak, Sep 28, 2007 IP