Jump to content

Guys, i really need help.......


Leon

Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<script language="javascript">
var smile = new Array(6);
var rotate=0;
var start;
smile [0]= new Image();
smile [0].src="smile0.jpg";
smile [1]= new Image();
smile [1].src="smile1.jpg";
smile [2]= new Image();
smile [2].src="smile2.jpg";
smile [3]= new Image();
smile [3].src="smile3.jpg";
smile [4]= new Image();
smile [4].src="smile4.jpg";
smile [5]= new Image();
smile [5].src="smile5.jpg";
function turn(){
if(rotate==5)
rotate=0;
else
++rotate;
document.smile.src=smile[rotate].src;
}
function turningpoint() {
if (start)
clearInterval(start);
start=setInterval("turn()",400);
}
</script>
<p><img src="smile0.jpg" name="smile"/> </p>
<form>
<input type="button" name="run" value=" Run " onclick="turningpoint();"/>
<input type="button" name="Stop" value=" Stop " onclick="clearInterval(start);"/>
</form>
</body>
</html>

 

I am trying to do a debug on this code but i cant find any errors. I have a few questions about this code.

1) "Sometime it works on desktop but not on expression web.

2) when i rename It has nothing to do with ''var Start" to other names it doesnt work. The stop button doesnt work.

For example :

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<script language="javascript">
var smile = new Array(6);
var rotate=0;
var begin;
smile [0]= new Image();
smile [0].src="smile0.jpg";
smile [1]= new Image();
smile [1].src="smile1.jpg";
smile [2]= new Image();
smile [2].src="smile2.jpg";
smile [3]= new Image();
smile [3].src="smile3.jpg";
smile [4]= new Image();
smile [4].src="smile4.jpg";
smile [5]= new Image();
smile [5].src="smile5.jpg";
function turn(){
if(rotate==5)
rotate=0;
else
++rotate;
document.smile.src=smile[rotate].src;
}
function turningpoint() {
if (begin)
clearInterval(begin);
start=setInterval("turn()",400);
}
</script>
<p><img src="../5/smile0.jpg" name="smile"/> </p>
<form>
<input type="button" name="run" value="Run" onclick="turningpoint();"/>
<input type="button" name="Stop" value="Stop" onclick="clearInterval(begin);"/>
</form>
</body>
</html>
OR
when i rename function turn() to function start() the run button doesnt function
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<script language="javascript">
var smile = new Array(6);
var rotate=0;
var go;
smile [0]= new Image();
smile [0].src="smile0.jpg";
smile [1]= new Image();
smile [1].src="smile1.jpg";
smile [2]= new Image();
smile [2].src="smile2.jpg";
smile [3]= new Image();
smile [3].src="smile3.jpg";
smile [4]= new Image();
smile [4].src="smile4.jpg";
smile [5]= new Image();
smile [5].src="smile5.jpg";
function start(){
if(rotate==5)
rotate=0;
else
++rotate;
document.smile.src=smile[rotate].src;
}
function turningpoint() {
if (go)
clearInterval(go);
start=setInterval("start()",400);
}
</script>
<p><img src="../5/smile0.jpg" name="smile"/> </p>
<form>
<input type="button" name="run" value="Run" onclick="turningpoint();"/>
<input type="button" name="Stop" value="Stop" onclick="clearInterval(go);"/>
</form>
</body>
</html>

post-190011-0-18973500-1446949823_thumb.jpg

post-190011-0-73556200-1446949823_thumb.jpg

post-190011-0-23399800-1446949824_thumb.jpg

post-190011-0-84570800-1446949824_thumb.jpg

post-190011-0-13977700-1446949825_thumb.jpg

post-190011-0-42331900-1446949825_thumb.jpg

Edited by Leon
Link to comment
Share on other sites

You are changing it to a variable that has no value applied to it, so it is null.If it is null the if condition will be false it will be ignored.

a variable that has no value applied to it? can you show me an example ? please?

a variable that has no value applied to it? can you show me an example ? please?

Link to comment
Share on other sites

It works OK! in better browsers, with crappy IE it fails as usual, maybe clearInterva() is overridden by setInterval() as it loops and IE being slow can't initiate clearInterval() in time, suggest you create new function and use clearInterval() within that to stop animation and remove if(start) condition.

Edited by dsonesuk
Link to comment
Share on other sites

It works OK! in better browsers, with crappy IE it fails as usual, maybe clearInterva() is overridden by setInterval() as it loops and IE being slow can't initiate clearInterval() in time, suggest you create new function and use clearInterval() within that to stop animation and remove if(start) condition.

which one it works ? the one with var start; ?

if the one with var start; works then why wouldnt the one with var go; doesnt work ? They are identical.

Link to comment
Share on other sites

The first one, the others won't because var go; is just declaration of empty var with no value, any reference to it will be empty nul value. Just compare it to all refereces of start, where if you look CAREFULLY it is assigned a specific method that runs a specific function (alert big clue here).

Edited by dsonesuk
Link to comment
Share on other sites

The first one, the others won't because var go; is just declaration of empty var with no value, any reference to it will be empty nul value. Just compare it to all refereces of start, where if you look CAREFULLY it is assigned a specific method that runs a specific function (alert big clue here).

sorry for saying this but i did compare it ...

 

i still dont see it... can u point out the code for me ..

Link to comment
Share on other sites

Terrible code. Why would you be testing a variable when you never gave it a value? Also you use the variable 'start' without declaring it.

im just following my professor example. THATS WHY IM CONFUSE.. var start doesnt have a declare but it works but var go doesnt ...

Link to comment
Share on other sites

Any variable declared within a function without starting with var is global and accessible outside and inside the function as though it was declared outside the function starting with var. That is why variable start is always working.A variable declared in function starting with var is only accessible within that function.var go; is just declaring a varible, it has no value, method, function, absolutely nothing applied to it later on within the script, yet you are testing for a value in the if condition which will ALWAYS be false because it has a empty, null value.That it! If you don't get now i should give it up.

  • Like 1
Link to comment
Share on other sites

Any variable declared within a function without starting with var is global and accessible outside and inside the function as though it was declared outside the function starting with var. That is why variable start is always working.A variable declared in function starting with var is only accessible within that function.var go; is just declaring a varible, it has no value, method, function, absolutely nothing applied to it later on within the script, yet you are testing for a value in the if condition which will ALWAYS be false because it has a empty, null value.That it! If you don't get now i should give it up.

well, i can always rename to var start as var go

for example :

post-190011-0-76032100-1447032878_thumb.png

this is how i look at the code

Edited by Leon
Link to comment
Share on other sites

Any variable declared within a function without starting with var is global and accessible outside and inside the function as though it was declared outside the function starting with var. That is why variable start is always working.A variable declared in function starting with var is only accessible within that function.var go; is just declaring a varible, it has no value, method, function, absolutely nothing applied to it later on within the script, yet you are testing for a value in the if condition which will ALWAYS be false because it has a empty, null value.That it! If you don't get now i should give it up.

the most importantly it was "start=setInterval("start()",400);" i have to change it to go=setInterval("turn()",400);

thanks
Link to comment
Share on other sites

BUT! in doing that, you have to replace every reference to start with go.

the most importantly it was "start=setInterval("start()",400);" i have to change it to go=setInterval("turn()",400);

 

this is the part where i ignored. im sorry for wasting your time.

But thankyou for everything

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...