Skip to main content
Known Participant
December 2, 2012
Answered

Display reminders at different intervals of time

  • December 2, 2012
  • 1 reply
  • 1539 views

Hi there!

My site is a SWF which loads on user requests data from a MySQL DB via PHP.

I have no problem mastering the whole communication process.

On the Home page, along with News which are already presented in the main right part of the page, I wish to display on the left part some reminders of essential services offered and also mandatory actions registered users must do when visiting the site.

Data for these reminders could be provided by the DB or from MovieClips (I prefer the first option as it is easier to change the reminders texts in the DB than in the SWF...).

The reminders should appear at different intervals of time.

Does anybody has an idea how can I set this up in Flash?

(ActionScript 2 ONLY)

Many thanks in advance for your help!

This topic has been closed for replies.
Correct answer Ned Murphy

If the timing needs to be done sequencially, then I'd probably use the setTimeout approach.  The basic scheme would be along the lines of...

- establish a counter variable = 0 (to increment thru the array)

- call a function that

    1) displays (arrayText[counter])  // r1 being the first

    2) increments the counter

    3) conditionally sets a timeout for "some" seconds  IF  counter < arrayText.length  // "some" defined somehow as msec (maybe based on a character count of the text being shown)

   

Have the setTimeout handler function be the same function as above so that it loads the next text, increments the counter, and sets a new timeout if another text is waiting in the array

So it would be something like the following...

     var counter:Number = 0;

     var textArray:Array = new Array();  // filled via your DB data

     function displayText(){

          tField,text = textArray[counter];

          var timeDelay:Number =  someFunction(tField.length);

          counter += 1;

          if(counter < textArray.length){    

                var sto = setTimeout(displayText, timeDelay);

          }

     }

     displayText(); // to start things off, but needs to be called after data is loaded

1 reply

Ned Murphy
Legend
December 2, 2012

You can use the setInterval function if you need to periodically perform processing.    If you need different intervals, then you either need to define more than one, or you need to redine the interval for a single one.

You could also use the setTimeout function if you need to have the intervals be sequencial.  When one completes, as part of the followup processing you define the next to be executed.

Germaris1Author
Known Participant
December 2, 2012

Thank you very much, Ned, for replying!

I understand the principles. But...

Say, for example, I have three reminders stored in three rows of a table.

Entering the frame, a sendAndLoad function calls the three reminders and stores them (in an array?), doing so, I only have one query to the DB and my DB Server is happy.  :-)

Reminders are short chunks of text (shorter than Twitter Messages...).

Length of each reminder is different from the others and thus takes a different time to be read. Say, r1 = 7 seconds, r2 = 5 seconds, r3 = 9 seconds... 

Which I can't figure out is how to set this up... i.e. triggering r2 when r1 is done, r3 when r2 is done and then r1 again when r3 is done.

I don't know if I make myself clear enough and if my explanation will be sufficient...

Sorry for the lack of details, just ask if you need more info.

Ned Murphy
Ned MurphyCorrect answer
Legend
December 2, 2012

If the timing needs to be done sequencially, then I'd probably use the setTimeout approach.  The basic scheme would be along the lines of...

- establish a counter variable = 0 (to increment thru the array)

- call a function that

    1) displays (arrayText[counter])  // r1 being the first

    2) increments the counter

    3) conditionally sets a timeout for "some" seconds  IF  counter < arrayText.length  // "some" defined somehow as msec (maybe based on a character count of the text being shown)

   

Have the setTimeout handler function be the same function as above so that it loads the next text, increments the counter, and sets a new timeout if another text is waiting in the array

So it would be something like the following...

     var counter:Number = 0;

     var textArray:Array = new Array();  // filled via your DB data

     function displayText(){

          tField,text = textArray[counter];

          var timeDelay:Number =  someFunction(tField.length);

          counter += 1;

          if(counter < textArray.length){    

                var sto = setTimeout(displayText, timeDelay);

          }

     }

     displayText(); // to start things off, but needs to be called after data is loaded