8 Replies Latest reply on Dec 5, 2012 5:08 AM by Germaris

    Display reminders at different intervals of time

    Germaris Level 1

      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!

        • 1. Re: Display reminders at different intervals of time
          Ned Murphy Adobe Community Professional & MVP

          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.

          1 person found this helpful
          • 2. Re: Display reminders at different intervals of time
            Germaris Level 1

            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.

            • 3. Re: Display reminders at different intervals of time
              Ned Murphy Adobe Community Professional & MVP

              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

              • 4. Re: Display reminders at different intervals of time
                Germaris Level 1

                Thank you so much, Ned!

                That's really a smart and elegant solution.

                Fully understood.

                 

                You know what? Sunday is the day my brain slows down...

                Could you imagine I didn't ever think about setting time in relation with real text length?

                Silly of me!

                 

                I'll tell you if it works when I'm done.

                • 6. Re: Display reminders at different intervals of time
                  Germaris Level 1

                  Hello!

                   

                  After a two day break, I got back to my hobby...

                  Alas, it turns bad... very bad...

                   

                  All I can get is the whole array visible in the text field.

                  No sequentially display...

                  Maybe ain't smart enough to set this up...

                   

                  Here's the code I use:

                  (You can assume that the PHP Script returns the array, it works nice)

                   

                  Code:

                   

                  // to display reminders for the registered user

                       displayRemindersFct = function () {

                               var myReminders = new LoadVars();

                               myReminders.action = "reminders";

                               myReminders.onLoad = function(ok) {

                                 _root.reminderFld.html = true;

                                  if (ok) {

                                      var counter:Number = 0;

                                      var myArray:Array = new Array(myReminders.mydata.split("|"));  // filled with DB data

                                      var how_many:Number = myArray.length;

                                      var finalString = "";

                                      var i = new LoadVars();

                                      for (i:Number = 1; i <= how_many; i++) {

                                           finalString = finalString + myArray[i] + "<br>";

                                      }

                                      _root.reminderFld.htmlText = finalString;

                                      function displayTextFct() {

                                           _root.reminderFld.htmlText = myArray[counter];

                                           var timeDelay:Number = _root.reminderFld.length;

                                           counter += 1;

                                           if (counter < myArray.length) {

                                                var sto = setTimeout(displayTextFct, timeDelay);

                                           }

                                      }

                                      displayTextFct();

                                 }

                                 else {

                                      stop();

                                 }

                            };

                            myReminders.sendAndLoad("misc.php",myReminders,'POST');

                       };

                       displayRemindersFct();

                  • 7. Re: Display reminders at different intervals of time
                    Ned Murphy Adobe Community Professional & MVP

                    There are a few things I can see that need attention, though there may be more that I don't.

                     

                    First and foremost, you should not be nesting functions within functions.  Break out your functions to stand by themselves.

                     

                    Another thing, you are looping with i starting at a value of 1.  Array indexes start at 0 (zero).

                     

                    Also, your time delay is set to be equal to the number of charcaters in the textfield.  The time delay value is specified as milliseconds.  So you probably want to use the numbers of characters to calculate some longer length of time.  Otherwise, things are likely to flash by faster than you can see them where only the last would be visible since it could all finish in the blink of an eye.

                    • 8. Re: Display reminders at different intervals of time
                      Germaris Level 1

                      Hi Ned!

                       

                      Thanks for your remarks.

                      To start afresh, I think I'll open a new thread which title will be:

                      "Sequentially display all of an array items, one after another"

                       

                      It will be better for the people seeking solution for this specific problem...

                       

                      Best regards

                       

                      Gerard