Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Flash - ActionScript

Code slightly off

 
Jump to:  
 
beesbane
PostPosted: Wed Jun 11, 2008 2:12 pm    Post subject: Code slightly off
       
I have the following code attached to the root and to the button that is meant
to make a slideshow. When clicked it should go, which it does. When clicked
again it should stop, which it doesn't. Instead it acts like a next button and
skips a page, but continues playing. Also I would like it to loop. Please tell
me what I am doing wrong.

on(press){
nextPage = _root.myBook.rightPageNumber
clearInterval(intervalID);
intervalID = setInterval(updateTimer, 2000);
updateTimer();
}

function updateTimer():Void {
nextPage++;
_root.myBook.gotoPage(nextPage);
if(nextPage >= _root.myBook.totalPages - 1){
clearInterval(intervalID);
}
}
 

 
kglad
PostPosted: Wed Jun 11, 2008 2:24 pm    Post subject: Re: Code slightly off
       
if by, "it should stop", you mean your setInterval() loop should terminate, use
a toggle boolean in your button's press handler:



on(press){
if(!this.toggle){
nextPage = _root.myBook.rightPageNumber
clearInterval(intervalID);
intervalID = setInterval(updateTimer, 2000);
updateTimer();
} else {
clearInterval(intervalID);
}
this.toggle = !this.toggle;
}
 

 
beesbane
PostPosted: Wed Jun 11, 2008 2:31 pm    Post subject: Re: Code slightly off
       
Thanks, that works great! How do I get it to loop though? So after the last one it goes back to the first.
 

 
kglad
PostPosted: Wed Jun 11, 2008 2:46 pm    Post subject: Re: Code slightly off
       
in updateTimer(), in your if-statement, remove that clearInterval() and reinitialize nextPage.
 

 
beesbane
PostPosted: Wed Jun 11, 2008 2:57 pm    Post subject: Re: Code slightly off
       
like this?

function updateTimer():Void {
nextPage++;
_root.myBook.gotoPage(nextPage);
if(nextPage >= _root.myBook.totalPages - 1){
nextPage;
}
}
 

 
beesbane
PostPosted: Wed Jun 11, 2008 2:57 pm    Post subject: Re: Code slightly off
       
like this?

function updateTimer():Void {
nextPage++;
_root.myBook.gotoPage(nextPage);
if(nextPage >= _root.myBook.totalPages - 1){
nextPage;
}
}
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

samochody Była to głupia miłość - Czerwone Gitary Dzwonki i Tapety opisy gg Szymon vel. Pasterz F. na 5H.PL - Strona domowa