Jump to content

No properties problem and misc. Q's


Lae.

Recommended Posts

Ok, so I am not waiting a week to sit and thisk on this one. Here's the snippet, and here's the full deal My n00b script

// Runs timer loop and increments picsfunction timer(){ this.incrementSrc() this.timerControl = setTimeout("timer()", this.counterTime) }// Increments the pic number, updates pic src and diplays updatefunction incrementSrc(){ var aNumber = this.picNumber aNumber++ alert(aNumber)  if (aNumber > numberOfPics)  { aNumber = 1  } this.newPicNumber(aNumber) this.newSrcName(sourceGenerator(this.picNumber)) document.getElementById(this.id).src = this.srcName }
Q1 - why does the setTimeout function take it's first argument as a string? And should it actually be this.timer() since it's object specific even if it's calling it's self? This whole method is built really... clumsy, even for me. I was having issues. Q2 - That issue being document.getElementById(this.id).src keeps ending up with no properties. (NaN) I got it so the first loop works.. but I can't get the 2nd loop functioning. So my guess is it doesn't know what this object is? I dunno. Let me know what you guys think. :) Thanks, Lae.
Link to comment
Share on other sites

hmmmm,You must be in the fast learners program. :)

<html><head>  <title></title><script type="text/javascript">var swapObjs = new Array();var j = -1;var stop = false;function imgObj(src, title, tm){this._img = new Image();this._img.src = src;this.title = title;this.tm = tm;this.showImg = showImg;swapObjs[swapObjs.length] = this;}function showImg(){var imgObj = document.getElementById('img1');imgObj.src = this._img.src;}new imgObj('http://w3schools.invisionzone.com/style_emoticons/default/smile.gif', 'Happy', 1000);new imgObj('http://w3schools.invisionzone.com/style_emoticons/default/ohmy.gif', 'Happy', 1000);new imgObj('http://w3schools.invisionzone.com/style_emoticons/default/mellow.gif', 'Somber', 1000);new imgObj('http://w3schools.invisionzone.com/style_emoticons/default/dry.gif', 'Dry', 1000);function doStuff(){if(stop) return;(j == swapObjs.length - 1)? j = 0 : j++;swapObjs[j].showImg();setTimeout('doStuff()', swapObjs[j].tm);}window.onload = doStuff;</script></head><body><img id="img1" src="http://w3schools.invisionzone.com/style_emoticons/default/dry.gif"   title="Dry" border="0" onmouseover="stop = true;" onmouseout="stop = false; doStuff();"></body></html>

Pretty cool that you want to step on into methods and objects.And yes setTimeout only accepts a string as it's first argument.Please post back if you have any questions.Thanks,

Edited by hacknsack
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...