13 Replies Latest reply on Jan 4, 2010 6:49 AM by d0brin

    Import value in AS from Imput text Field

    d0brin Level 1

      Hey i want to ask something. In this count down code that i have placed below. It has an exact counting value. My question is how to make so that a user can enter his own countdown values from imput text fields? The whole .swf looks like this: first the user opens the screen he enter his value for minutes and secs in imput text fields and than the countdown starts so how to link the imput text fields to import the value for minutes and seconds in to the AS for the count down? pls help

       

      Here is the Code that i use for the time countdown:

       

      start_time = getTimer();
      countdown = 600000;
      onEnterFrame = function () {
          elapsed_time = getTimer()-start_time;
          _root.count.text = time_to_string(elapsed_time);
          _root.count_down.text = time_to_string(_root.countdown-elapsed_time);
      };
      function time_to_string(time_to_convert) {
          elapsed_hours = Math.floor(time_to_convert/3600000);
          remaining = time_to_convert-(elapsed_hours*3600000);
          elapsed_minutes = Math.floor(remaining/60000);
          remaining = remaining-(elapsed_minutes*60000);
          elapsed_seconds = Math.floor(remaining/1000);
          remaining = remaining-(elapsed_seconds*1000);
          elapsed_msecs = Math.floor(remaining/10);
         
          if (elapsed_hours<10) {
              hours = "0"+elapsed_hours.toString();
          } else {
              hours = elapsed_hours.toString();
          }
          if (elapsed_minutes<10) {
              minutes = "0"+elapsed_minutes.toString();
          } else {
              minutes = elapsed_minutes.toString();
          }
          if (elapsed_seconds<10) {
              seconds = "0"+elapsed_seconds.toString();
          } else {
              seconds = elapsed_seconds.toString();
          }
            if (elapsed_msecs<10) {
              msecs = "0"+elapsed_msecs.toString();
          } else {
              msecs = elapsed_msecs.toString();
          }
         
          return minutes+":"+seconds+"."+msecs;
      }

        • 1. Re: Import value in AS from Imput text Field
          kglad Adobe Community Professional & MVP

          assuming you use a movieclip button (named countdownBtn) to start the countdown and your input textfields are minutesTF and secondsTF, use:

           

          countdownBtn.onRelease = function(){
          start_time = getTimer();
          countdown = 60000*Number(minutesTF.text)+1000*Number(secondsTF.text);
          this.onEnterFrame = countdownF;
          }

           


          function countdownF() {
              elapsed_time = getTimer()-start_time;
              _root.count.text = time_to_string(elapsed_time);
              _root.count_down.text = time_to_string(_root.countdown-elapsed_time);

          if(Number(_root.count_down.text)<=0){

          delete coundownBtn.onEnterFrame;

          }

          };
          function time_to_string(time_to_convert) {
              elapsed_hours = Math.floor(time_to_convert/3600000);
              remaining = time_to_convert-(elapsed_hours*3600000);
              elapsed_minutes = Math.floor(remaining/60000);
              remaining = remaining-(elapsed_minutes*60000);
              elapsed_seconds = Math.floor(remaining/1000);
              remaining = remaining-(elapsed_seconds*1000);
              elapsed_msecs = Math.floor(remaining/10);
             
              if (elapsed_hours<10) {
                  hours = "0"+elapsed_hours.toString();
              } else {
                  hours = elapsed_hours.toString();
              }
              if (elapsed_minutes<10) {
                  minutes = "0"+elapsed_minutes.toString();
              } else {
                  minutes = elapsed_minutes.toString();
              }
              if (elapsed_seconds<10) {
                  seconds = "0"+elapsed_seconds.toString();
              } else {
                  seconds = elapsed_seconds.toString();
              }
                if (elapsed_msecs<10) {
                  msecs = "0"+elapsed_msecs.toString();
              } else {
                  msecs = elapsed_msecs.toString();
              }
             
              return minutes+":"+seconds+"."+msecs;
          }

          • 2. Re: Import value in AS from Imput text Field
            d0brin Level 1

            Yeah thanks a lot that helped me alot just a small thing...how to make it when it reaches 0 to go to a certain frame?

            • 3. Re: Import value in AS from Imput text Field
              kglad Adobe Community Professional & MVP

              if you're still able, please mark this thread as answered:

               


              countdownBtn.onRelease = function(){
              start_time = getTimer();
              countdown = 60000*Number(minutesTF.text)+1000*Number(secondsTF.text);
              this.onEnterFrame = countdownF;
              }

               


              function countdownF() {
                  elapsed_time = getTimer()-start_time;
                  _root.count.text = time_to_string(elapsed_time);
                  _root.count_down.text = time_to_string(_root.countdown-elapsed_time);

              if(Number(_root.count_down.text)<=0){

              delete coundownBtn.onEnterFrame;

              whatevermovieclip.gotoAndPlay(whateverframenumberorlabel);

              }

              };
              function time_to_string(time_to_convert) {
                  elapsed_hours = Math.floor(time_to_convert/3600000);
                  remaining = time_to_convert-(elapsed_hours*3600000);
                  elapsed_minutes = Math.floor(remaining/60000);
                  remaining = remaining-(elapsed_minutes*60000);
                  elapsed_seconds = Math.floor(remaining/1000);
                  remaining = remaining-(elapsed_seconds*1000);
                  elapsed_msecs = Math.floor(remaining/10);
                 
                  if (elapsed_hours<10) {
                      hours = "0"+elapsed_hours.toString();
                  } else {
                      hours = elapsed_hours.toString();
                  }
                  if (elapsed_minutes<10) {
                      minutes = "0"+elapsed_minutes.toString();
                  } else {
                      minutes = elapsed_minutes.toString();
                  }
                  if (elapsed_seconds<10) {
                      seconds = "0"+elapsed_seconds.toString();
                  } else {
                      seconds = elapsed_seconds.toString();
                  }
                    if (elapsed_msecs<10) {
                      msecs = "0"+elapsed_msecs.toString();
                  } else {
                      msecs = elapsed_msecs.toString();
                  }
                 
                  return minutes+":"+seconds+"."+msecs;
              }

              • 4. Re: Import value in AS from Imput text Field
                d0brin Level 1

                yeah but it doesnt work cuz what happens is that the movie is starting to loop on the desgnated frame

                 

                if(Number(_root.count_down.text)<=0){
                delete coundownBtn.onEnterFrame;
                destruct_mc.gotoAndPlay("action");
                }

                 

                and when the countdown reaches 00:00.0 it start counting down again from 60min 59sec ... pls help :X what to do? how to make it to stop on 0 and to play the desginated movie clip frame.....?

                • 5. Re: Import value in AS from Imput text Field
                  kglad Adobe Community Professional & MVP

                  it won't countdown more than once unless you did something wrong.  does the frame that contains that code, play more than once?  is countdownBtn a movieclip?

                  • 6. Re: Import value in AS from Imput text Field
                    d0brin Level 1

                    yes but i made the code on 2 separate frames on frame 1 i placed the movie clip with the btn funciton and the imput text fields that determinate my countdown time with this code: (btw i made the imput text fileds movie clips cuz it turns out that if i want my timer to work on frame 2 i must have those text fields on frame 2 but i dont want to see them so i made them a movie clip and when the movie enters on frame 2 it has this code: pow_mc._visible = false; Any way the code i have placed on frame 1 is:


                    countdownBtn.onRelease = function(){
                        gotoAndPlay(2);
                        countdown = 60000*Number(_root.pow_mc.minutesTF.text)+1000*Number(_root.pow_mc.secondsTF.text);   
                    }
                    _root.pow_mc.minutesTF.text = "00" ;
                    _root.pow_mc.secondsTF.text = "00" ;

                     

                     

                     

                    and on frame 2 i placed the actual count down dynamic text field with this code:

                     

                    start_time = getTimer();
                    countdown = 60000*Number(_root.pow_mc.minutesTF.text)+1000*Number(_root.pow_mc.secondsTF.text);
                    this.onEnterFrame = countdownF;

                     

                    function countdownF() {
                        elapsed_time = getTimer()-start_time;
                        _root.count.text = time_to_string(elapsed_time);
                        _root.count_down.text = time_to_string(_root.countdown-elapsed_time);
                       
                        if(Number(_root.count_down.text)<=0){
                            delete coundownBtn.onEnterFrame;
                            destruct_mc.gotoAndPlay("action");
                        }
                    };

                     

                    function time_to_string(time_to_convert) {
                        elapsed_hours = Math.floor(time_to_convert/3600000);
                        remaining = time_to_convert-(elapsed_hours*3600000);
                        elapsed_minutes = Math.floor(remaining/60000);
                        remaining = remaining-(elapsed_minutes*60000);
                        elapsed_seconds = Math.floor(remaining/1000);
                        remaining = remaining-(elapsed_seconds*1000);
                        elapsed_msecs = Math.floor(remaining/10);
                       
                        if (elapsed_hours<10) {
                            hours = "0"+elapsed_hours.toString();
                        } else {
                            hours = elapsed_hours.toString();
                        }
                        if (elapsed_minutes<10) {
                            minutes = "0"+elapsed_minutes.toString();
                        } else {
                            minutes = elapsed_minutes.toString();
                        }
                        if (elapsed_seconds<10) {
                            seconds = "0"+elapsed_seconds.toString();
                        } else {
                            seconds = elapsed_seconds.toString();
                        }
                          if (elapsed_msecs<10) {
                            msecs = "0"+elapsed_msecs.toString();
                        } else {
                            msecs = elapsed_msecs.toString();
                        }
                       
                        return minutes+":"+seconds+"."+msecs;
                    }

                     

                    stop();

                     

                    is there something wrong that i made? and with this way i have made the code the problem i mensioned before happened.....what to do?

                    • 7. Re: Import value in AS from Imput text Field
                      kglad Adobe Community Professional & MVP

                      the code i gave should only execute once.

                      • 8. Re: Import value in AS from Imput text Field
                        d0brin Level 1

                        yeah but it doesnt i even have created a sample whare it is only the timer on one frame...and when it goes to 0 it starts again couting...form 60minm and 59 secs.... and also it doesnt want to complete the function when it reaches 0 cuz it activates it before it reches it at the minute you press the movie clip btn it completes the function.... i have created a sample. I will Attach it to see.

                        • 9. Re: Import value in AS from Imput text Field
                          kglad Adobe Community Professional & MVP

                          is countdownBtn a movieclip?  does the frame that contains that code play only once?

                          • 10. Re: Import value in AS from Imput text Field
                            d0brin Level 1

                            yes its all as it should be... just look at the sample and see how its playing over and over again i dont know why it is happening like this :X

                            • 11. Re: Import value in AS from Imput text Field
                              d0brin Level 1

                              okey thank you for everything. I have found a way to achieve what i want i wanted after it ends to go to a certain frame and what i did was to add this code to the countdown code:

                               

                              delay = setInterval(proceed, countdown);

                              function proceed() {
                                  clearInterval(delay);
                                  gotoAndPlay(3);
                              }

                               

                              and it works fine, but i am stil curious about that timer wount stop thing

                              • 12. Re: Import value in AS from Imput text Field
                                kglad Adobe Community Professional & MVP

                                use:

                                 

                                if (_root.countdown-elapsed_time<=0) {

                                 

                                instead of:

                                 

                                if (Number(_root.count_down.text)<=0) {

                                • 13. Re: Import value in AS from Imput text Field
                                  d0brin Level 1

                                  ok i will try