WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Some problems with Object Oriented Javascript, iDRiS, March 5, 2004
     Re:Some problems with Object Oriented Javascript, Saint Jude, March 5, 2004
         Re:Some problems with Object Oriented Javascript, iDRiS, March 5, 2004

Subject: Some problems with Object Oriented Javascript From: iDRiS Date: March 5, 2004

Hi guys, I'm trying to make this thing in Javascript, but one part is not working.  I have pasted the code below.  Basically, when I call myTemplate.generatePicker(myDiv); everything works fine, except when I attachEvent in IE, i have it call this.mOver which calls tempalteMOver in the object because I then want to pass this.imgObj to a function from there.  However, this.imgObj is not working... For example I have it alerting right now and it does not alert the imgObj, it just says undefined.  I tried some other combinations, taking out this's and whatnot but with no luck.  Please help! :) Thanks

-iDRiS

/*Code begins here:: */

function Template(templateName, defaultID, defaultColor, thumbLoc) {
//define local properties
 this.name = templateName;
 this.colors = [];
// this.description = templateDesc;
 this.imgObj = document.createElement("IMG");
 this.tableObj = document.createElement("Table");

 this.colors[0] = new Color(defaultID,defaultColor,thumbLoc);


//attach object's methods
 this.addColor = templateAddColor;
 this.mOver = templateMOver;
 this.mOut = templateMOut;
 this.mClick = templateMClick;
 this.generatePicker = templateGeneratePicker;
}

function templateAddColor(colorID, newColor, thumbLoc) {
 this.colors[this.colors.length] = new Color(colorID,newColor,thumbLoc);
}

function templateMOver() {
 alert(this.imgObj);
// mOverTemplate(this);
}
function templateMOut() {
 alert(this.imgObj);
// mOutTemplate(this.imgObj);
}
function templateMClick() {
 mClickTemplate(this.imgObj);
}

function templateGeneratePicker(container) {
 elImg = this.imgObj;
 elImg.id = this.name;
 elImg.src = this.colors[0].thumbLoc;
 elImg.className = "tempImage";
 elImg.width = 100;
 elImg.height = 100;
 if(document.all) {
  elImg.attachEvent("onmouseover", this.mOver);
  elImg.attachEvent("onmouseout", this.mOut);
  elImg.attachEvent("onclick", this.mClick);
 } else {
  elImg.setAttribute("onMouseOver","mOverTemplate(this);");
  elImg.setAttribute("onMouseOut","mOutTemplate(this);");
  elImg.setAttribute("onClick","mClickTemplate(this);");
 }
 container.appendChild(elImg);

 elTable = this.tableObj;
 elTable.id = this.name + 'colors';
 elTable.style.display = 'none';
 for(i=0;i<this.colors.length;i++) {
  elRow = elTable.insertRow(i);
  elCell = elRow.insertCell(0);
  elCell.bgColor = this.colors[i].htmlColor;
  elCell.className = 'tempColor';
  elCell.setAttribute("onMouseOver","changeColor('"+elImg.id+"','"+this.colors[i].thumbLoc+"');");
  elCell.setAttribute("onClick","setTemplate('"+elImg.id+this.colors[i].htmlColor+"');");
  elCell.innerHTML = "&nbsp;";
 }
 container.appendChild(elTable);
}

 

function Color(colorID, htmlColor, thumbLoc) {
//define local properties
 this.styleID = colorID;
 this.htmlColor = htmlColor;
 this.thumbLoc = thumbLoc;
//attach object's methods
 
}




Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX