|  | Code slightly off |  | |
| | | beesbane |  |
| Posted: 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 |  |
| Posted: 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 |  |
| Posted: 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 |  |
| Posted: 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 |  |
| Posted: 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 |  |
| Posted: 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; } } |
| |
|
|