I agree... periodical is the easiest way to go

On Wed, Oct 1, 2008 at 8:38 AM, liam.smart <[EMAIL PROTECTED]> wrote:

>
> Hi jonib & Nathan,
>
> Im thinking its going to impossible for me to get the function to loop
> 1 after the other since I calculate the time due to the random speed.
>
> So maybe I should just make sure it loops every 10 seconds or so. I
> already set the max length of each array instance to 28 characters, so
> 28x(0.35 sec max) = 9.8.
>
> Either that or dump the random delay so I can calculate the exact time
> its going to take. The BBC uses a setInterval function, so im
> guessing .periodical() is the MooTools way?
>
> On Oct 1, 2:17 am, jonlb <[EMAIL PROTECTED]> wrote:
> > You might be able to make this work by using the mootools function
> > periodical:
> >
> > http://mootools.net/docs/Native/Function/#Function:periodical
> >
> > It's just the beginning of a thought and I haven't fleshed it out much
> > but it might help....
> >
> > jonlb
> >
> > On Sep 29, 1:34 pm, "liam.smart" <[EMAIL PROTECTED]> wrote:
> >
> > > Hi all,
> >
> > > Im new to MooTools and Javascript but I have accomplished a fair bit
> > > in a short time. One thing I'm not really sure how to do, is loop a
> > > function repeatedly. I have modified the code at the bottom to try and
> > > get a looping version.
> >
> > > I am trying to create a news ticker like on the BBC website. Just now,
> > > it just displays the last instance in the array, but I need to keep
> > > cycling through all the instances in the array, and then start from
> > > the start again.
> >
> > > I have thought about getting the length of the string, multiplying
> > > that by the speed, and then doing a set-interval to call the function,
> > > but the speed varies so that option will not work.
> >
> > > I then thought about doing a for loop and when x == the length of the
> > > array, start the function again. But the ticker is just reading the
> > > last instance.
> >
> > > I don't need some-one to do this for me, but just need pointed in the
> > > right direction. Should I be using the .delay() method, or is
> > > the .periodical() one the one I want? Do I need to create a chain? Its
> > > a fair bit of code to post so will just post the important bits
> > > (hopefully people can see what I'm trying to do here. After it has
> > > went through the array, start again, but obviously the loop is
> > > finishing quicker than the actual ticker, so that what makes me think
> > > I need to chain the functions and set delays...):
> >
> > > [start code]
> > > //initialization
> > > initialize: function(options)
> > > {
> > >         //set options
> > >         this.setOptions(options);
> >
> > >         //remove 'Hidden' class
> > >         if(this.options.container.hasClass('Hidden'))
> > >         {
> > >                 this.options.container.removeClass('Hidden');
> > >         };
> >
> > >         //retrieve/split/set new html
> > >         this.options.initString = this.options.container.innerHTML
> > >         this.options.splitString = this.options.initString.split(',');
> > >         this.options.container.set('html','<span>Latest:</span>');
> >
> > > },
> >
> > > //start the blogTicker
> > > start: function()
> > > {
> > >         //set new news items from split string
> > >         this.options.message =
> > > this.options.splitString[this.options.counter];
> >
> > >         //for every letter
> > >         for(x = 0; x < this.options.message.length; x++)
> > >         {
> > >                 //spits out characters at random pace
> > >                 var pace = (this.options.delay * x) +
> > > $random(0,this.options.variance);
> > >                 var current = this.options.message.charAt(x);
> >
> > >                 //spit out the letter or delete one if backChar is
> encountered
> > >                 if(current != this.options.backChar)
> > >                 {
> > >                         var go = this.setLetter.delay(pace,this);
> > >                 }
> > >                 else
> > >                 {
> > >                         var go = this.deleteLetter.delay(pace +
> > > this.options.backDelay,this);
> > >                 };
> > >         };
> >
> > >         if(this.options.counter > this.options.splitString.length-1)
> > >         {
> > >                 this.options.counter = 0;
> > >                 this.initialize();
> > >         }
> > >         else
> > >         {
> > >                 this.options.counter++;
> > >         };
> >
> > > },
> >
> > > //place the newest letter in the container
> > > setLetter: function()
> > > {
> > >         //push string into the links now character by character
> > >
> this.options.container.set('html',this.options.container.get('html')
> > > + '' + this.options.message.charAt(this.options.cursor));
> >
> > >         //increment cursor
> > >         this.options.cursor++;},
> >
> > > [end code]
> >
> > > Like I said, I'm not here for a free ride, I just need pointed in the
> > > right direction as I have seriously spent a lot of time trying
> > > different things.
> >
> > > Many thanks,
> > > Liam
>

Reply via email to