Current location: Hot Scripts Forums » General Web Coding » JavaScript » How can I use setTimeout() function with a class ?!


How can I use setTimeout() function with a class ?!

Reply
  #1 (permalink)  
Old 11-23-06, 02:24 PM
Spartakis Spartakis is offline
New Member
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question How can I use setTimeout() function with a class ?!

I am trying to program a class to draw some clocks in the same page. But I don't manage to use setTimeout() to call a method in the class ...
This method is used to refresh the hour on the clock.

I hope I have been enough clear but if you want to ask me some questions more, I will be happy to answer it.

Spartakis
Reply With Quote
  #2 (permalink)  
Old 11-23-06, 02:47 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Can you post your code?
Reply With Quote
  #3 (permalink)  
Old 11-23-06, 02:57 PM
Spartakis Spartakis is offline
New Member
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
For sure :

Code:
function test(num) {


	//Variables à modifier :

	//Les couleurs :
	this.fCol='7777BB'; //couleur des chiffres.
	this.sCol='9999FF'; //couleur des secondes.
	this.mCol='666699'; //couleur des minutes.
	this.hCol='000066'; //couleur des heures.	 

	//position en absolut :
	this.Xoff=100*(num-0.5);  //à gauche
	this.Yoff=47; //en haut

	//taille
	this.Ybase=34; //hauteur
	this.Xbase=34; //largeur

	


	//ne pas modifier ci-après :
	this.H='...';
	this.H=this.H.split('');
	this.M='....';
	this.M=this.M.split('');
	this.S='.....';
	this.S=this.S.split('');

	this.NS4=(document.layers);
	this.NS6=(document.getElementById&&!document.all);
	this.IE4=(document.all);

	this.Ypos=0;
	this.Xpos=0;
	this.dots=12;
	this.Split=360/this.dots;

	if(this.NS6) {
		for(i=1; i < this.dots+1; i++) {
			with(this) document.write('<div id="n6Digits'+i+num+'" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial;font-size:10px;color:#'+fCol+';text-align:center;padding-top:10px">'+i+'</div>');
		}
		for(i=0; i < this.M.length; i++) {
			with(this) document.write('<div id="Ny'+i+num+'" style="position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background:#'+mCol+'"></div>');
		}
		for(i=0; i < this.H.length; i++) {
			with(this) document.write('<div id="Nz'+i+num+'" style="position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background:#'+hCol+'"></div>');
		}
		for(i=0; i < this.S.length; i++) {
			with(this) document.write('<div id="Nx'+i+num+'" style="position:absolute;top:0px;left:0px;width:2px;height:2px;font-size:2px;background:#'+sCol+'"></div>');
		}
	}

}

function clock(num,fuseau){
	//raffraichissement :
	//this.refr=500;
	
	this.time = new Date ();
	this.secs = this.time.getSeconds();
	this.sec = -1.57 + Math.PI * this.secs/30;
	this.mins = this.time.getMinutes();
	this.min = -1.57 + Math.PI * this.mins/30;
	this.hr = this.time.getHours();
	this.hr = this.hr+fuseau;
	this.hrs = -1.57 + Math.PI * this.hr/6 + Math.PI*parseInt(this.time.getMinutes())/360;

	if(this.NS6) {
		this.Ypos=this.Yoff;
		this.Xpos=this.Xoff;
		
		for(i=1; i < this.dots+1; i++) {
			with(this) document.getElementById("n6Digits"+i+num).style.top=Ypos-15+Ybase*Math.sin(-1.56 +i *Split*Math.PI/180)
			with(this) document.getElementById("n6Digits"+i+num).style.left=Xpos-15+Xbase*Math.cos(-1.56 +i *Split*Math.PI/180)
		}
		for(i=0; i < this.S.length; i++) {
			with(this) document.getElementById("Nx"+i+num).style.top=Ypos+i*Ybase/4.1*Math.sin(sec);
			with(this) document.getElementById("Nx"+i+num).style.left=Xpos+i*Xbase/4.1*Math.cos(sec);
		}
		for(i=0; i < this.M.length; i++) {
			with(this) document.getElementById("Ny"+i+num).style.top=Ypos+i*Ybase/4.1*Math.sin(min);
			with(this) document.getElementById("Ny"+i+num).style.left=Xpos+i*Xbase/4.1*Math.cos(min);
		}
		for(i=0; i < this.H.length; i++) {
			with(this) document.getElementById("Nz"+i+num).style.top=Ypos+i*Ybase/4.1*Math.sin(hrs);
			with(this) document.getElementById("Nz"+i+num).style.left=Xpos+i*Xbase/4.1*Math.cos(hrs);
		}
	}
	
	window.setTimeout('this.clock', 500);
}

test.prototype.clock=clock;

clock1=new test(1);
clock2=new test(2);
clock3=new test(3);
clock4=new test(4);


clock1.clock(1, +1);
clock2.clock(2, -5);
clock3.clock(3, +0);
clock4.clock(4, -1);
I'm a beginner in javascript and I try to change an existing code to make what I want ...
Reply With Quote
  #4 (permalink)  
Old 11-26-06, 02:44 PM
reportingsjr reportingsjr is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
You dont define any class anywhere. That might be an issue.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A little help with a class please :) HairySpider PHP 2 04-10-06 04:06 AM
Parsing XML dodotopia PHP 1 02-08-06 03:51 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 11:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.