Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2009, 06:12 PM   PM User | #1
calebandchels
Regular Coder

 
Join Date: Nov 2009
Location: Florida United States
Posts: 104
Thanks: 5
Thanked 2 Times in 2 Posts
calebandchels is an unknown quantity at this point
Need help with this script for animating pic new to forum!!!!!

Hi Im new here and just recently getting into coding and I can't seem to figure what my problem is. I am using this to simulate a picture fading into another. After it finishes one cycle of the imgList it doesnt renew the first picture, it shows it as an invalid link. Any ideas?

Caleb

<script type="text/javascript">
//animate header

//use array to make list of images
var imgList=new Array(
"Live Graphics/header1A.gif",
"Live Graphics/header1A.gif",
"Live Graphics/header1A.gif",
"Live Graphics/header1A.gif",
"Live Graphics/header1A.gif",
"Live Graphics/header1b.gif",
"Live Graphics/header1c.gif",
"Live Graphics/header1d.gif",
"Live Graphics/header1e.gif",
"Live Graphics/header1f.gif",
"Live Graphics/header1g.gif"
);

var frame=1;
var spriteImage

function init(){
setInterval("animate()",200);
spriteImage=document.getElementById("image");
};//end init

function animate(){
frame++ ;
if (frame>imgList.length){
frame=1;
}//end if
spriteImage.src=imgList[frame];
}
</script>
calebandchels is offline   Reply With Quote
Old 11-05-2009, 06:17 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
try to change to this:
Code:
function animate(){
	frame++	;
	if (frame >= imgList.length){
		frame=0; 
	}//end if
	spriteImage.src=imgList[frame];
}
when frame is equal with imgList.length point out of the array.

best regards
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
calebandchels (11-05-2009)
Old 11-05-2009, 06:23 PM   PM User | #3
calebandchels
Regular Coder

 
Join Date: Nov 2009
Location: Florida United States
Posts: 104
Thanks: 5
Thanked 2 Times in 2 Posts
calebandchels is an unknown quantity at this point
It worked perfect but just to clarify for the future, because the function pointed directly to the array that was the problem?

Thank you
Caleb

Quote:
Originally Posted by oesxyl View Post
try to change to this:
Code:
function animate(){
	frame++	;
	if (frame >= imgList.length){
		frame=0; 
	}//end if
	spriteImage.src=imgList[frame];
}
when frame is equal with imgList.length point out of the array.

best regards
calebandchels is offline   Reply With Quote
Old 11-05-2009, 06:26 PM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by calebandchels View Post
It worked perfect but just to clarify for the future, because the function pointed directly to the array that was the problem?

Thank you
Caleb
no. The array have length elements and start from 0, that means last element will have index length-1, the index length is out of range.
I try a poor explanation of this in my previous post.,

best regards
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:53 AM.


Advertisement
Log in to turn off these ads.