22 Replies Latest reply on Aug 22, 2018 5:21 AM by kazemb33155285

    create a countdown

    netartdesign Level 1

      hi

      i want to create 2 differnt countdown. i have tried so many scripts and variations allready but failed.

      1st one is a 10.00 minutes countdown that goes down very fast and ends whithin 12 seconds. 2nd is a simple 100-0 countdown in 12 seconds as well. they start and end at same frames.

      i want to make them both in as3.0 and then place them in an existing fla.

      never did it before and saw some stuff on the web but couldnt manage with what i found.

      thanks.

        • 1. Re: create a countdown
          Ned Murphy Adobe Community Professional & MVP

          Search Google using "AS3 countdown" and you should find some tutorials to explain how you can do it.

          • 2. Re: create a countdown
            netartdesign Level 1

            hey ned

            i was looking all over google and couldnt find something that i can work with.most of them were as2 and the as3 i found were'nt good for what i need.

            p.s the reasson im looking for as3 is beacause i need to place them in a as3 file animation that i created.

            thank so much.

            • 3. Re: create a countdown
              kglad Adobe Community Professional & MVP

              you can use the following for a countdown timer.  to format as time, add a format function to f:

               

              var t:Timer;

               

              // count down frame from 2nd param to 1st param over 3rd param ms and display in textfield tf
              countDownF(5,10,5000,tf);

              function countDownF(nStart:int,nEnd:int,duration:uint,tf:TextField) {
                  if (nStart>=nEnd) {
                      return null;
                  } else {
                      t = new Timer(duration/(nEnd-nStart),nEnd-nStart);
                      t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f(e,nEnd,tf)});
                      t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));
                      t.start();
                  }
              }

              function f(e:TimerEvent,nEnd:int,tf:TextField){
                  tf.text = (nEnd-e.target.currentCount).toString();
              }

              • 4. Re: create a countdown
                netartdesign Level 1

                hey

                i succieded doing the first countdown from 100 to 0. works great.

                i didnt understand hot to make the 10 minutes countdown script. in adittion

                i need it to go fast in 10 seconds. what should i put in the script?

                thanks.

                • 5. Re: create a countdown
                  kglad Adobe Community Professional & MVP

                  to format as time, add a format function to f:

                   

                  the 3rd parameter is duration of the countdown.  decrease it if you want the countdown to proceed more quickly.

                  1 person found this helpful
                  • 6. Re: create a countdown
                    netartdesign Level 1

                    how do i do that?

                    • 7. Re: create a countdown
                      kglad Adobe Community Professional & MVP

                      which?

                      1 person found this helpful
                      • 8. Re: create a countdown
                        netartdesign Level 1

                        how do i format the fuction f: ? what should i write there?

                        • 9. Re: create a countdown
                          kglad Adobe Community Professional & MVP

                          i don't know how you want the time formated but you'll use something like:

                           


                          function  countDownF(nStart:int,nEnd:int,duration:uint,tf:TextField) {
                              if  (nStart>=nEnd) {
                                  return null;
                              } else {
                                  t  = new Timer(duration/(nEnd-nStart),nEnd-nStart);
                                   t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f(e,nEnd,tf)});
                                   t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));
                                   t.start();
                              }
                          }

                          function  f(e:TimerEvent,nEnd:int,tf:TextField){
                              tf.text = formatF( (nEnd-e.target.currentCount));
                          }


                          function formatF(n:int):String{

                          var hrs:int = Math.floor(n/3600);

                          var min:int = Math.floor((n-hrs*3600)/60);

                          var sec:int = n-hrs*3600-min*60;

                          var a:Array = [hrs.toString(),min.toString(),sec.toString()];

                          for(var i:uint=0;i<a.length;i++){

                          while(a[i].length<2){

                          a[i]="0"+a[i];

                          }

                          }

                          return a[2]+":"+a[1]+":"+a[0];

                          }

                          • 10. Re: create a countdown
                            netartdesign Level 1

                            hey

                            it didnt work out when i tried it.

                            thats what i did:

                            i have acreated a dynmic text field. embed ed it. gave it instance name of

                            tf. copy paste your last script. didnt work.

                            i nedd a countdown that will start at 10:00 finish at 00:00 and run in 12

                            seconds....

                            i was trying to mix togethor both scripts too but guess what,,,didnt work!

                            thanks.

                            • 11. Re: create a countdown
                              netartdesign Level 1

                              hello again.

                              so i was trying everything but it didnt work out.

                              can you help me with the script you gave me? im trying to make a 10 minutes

                              countdown timer that will run from 10:00 to00:00 in 12 sec. i need it in

                              as3. the thing is i know more or less how to do it in as2 but the as3

                              killed. i need to place it in as3 document.

                              thanks again.

                              • 12. Re: create a countdown
                                kglad Adobe Community Professional & MVP

                                it works fine:  www.kglad.com/Files/forums/Untitled-1.fla

                                 

                                p.s.  please mark, at least, one of my responses as having answered your question.

                                • 13. Re: create a countdown
                                  netartdesign Level 1

                                  hi

                                  ok after i made a few changes it fit to what i need!

                                  thank you so much!!!i mark the answers.

                                  now the only thing is that beacause i have 2 differnt coundown in my fla. (1st from 100 to 0 and the 2nd from 10:00 to 00:00) it give me an error of a duplicate function definition in 2 places in my script. how can i avoid that?

                                  thanks.

                                  • 14. Re: create a countdown
                                    kglad Adobe Community Professional & MVP

                                    use something like:

                                     

                                     

                                    countDown1F(0,1000,5000,tf1);

                                    countDown2F(0,500,1000,tf2);

                                     

                                    function   countDown2F(nStart:int,nEnd:int,duration:uint,tf:TextField) {
                                        if    (nStart>=nEnd) {
                                            return null;
                                        } else {
                                              var t:Timer  = new Timer(duration/(nEnd-nStart),nEnd-nStart);
                                              t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f2(e,nEnd,tf)});
                                               t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));
                                              t.start();
                                        }
                                    }

                                    function   f2(e:TimerEvent,nEnd:int,tf:TextField){
                                        tf.text = nEnd-e.target.currentCount;
                                    }

                                     

                                    function   countDown1F(nStart:int,nEnd:int,duration:uint,tf:TextField) {
                                        if   (nStart>=nEnd) {
                                            return null;
                                        } else {
                                             var t:Timer  = new Timer(duration/(nEnd-nStart),nEnd-nStart);
                                              t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f1(e,nEnd,tf)});
                                              t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));
                                              t.start();
                                        }
                                    }

                                    function   f1(e:TimerEvent,nEnd:int,tf:TextField){
                                        tf.text = formatF(  (nEnd-e.target.currentCount));
                                    }


                                    function  formatF(n:int):String{

                                    var  hrs:int = Math.floor(n/3600);

                                    var  min:int = Math.floor((n-hrs*3600)/60);

                                    var sec:int = n-hrs*3600-min*60;

                                    var a:Array =  [hrs.toString(),min.toString(),sec.toString()];

                                    for(var i:uint=0;i<a.length;i++){

                                    while(a[i].length<2){

                                    a[i]="0"+a[i];

                                    }

                                    }

                                    return a[2]+":"+a[1]+":"+a[0];

                                    }

                                    • 15. Re: create a countdown
                                      netartdesign Level 1

                                      hi

                                      made 3 dynimc texfield.

                                      named them tf1 tf2.

                                      copy paste your script and put it at the same frame.

                                      edit the script according to the timer i needed.

                                       

                                       

                                      countDown1F(0,600,5400,tf1);

                                      countDown2F(0,100,5400,tf2);

                                       

                                      function   countDown2F(nStart:int,nEnd:int,duration:uint,tf:TextField) {

                                          if    (nStart>=nEnd) {

                                              return null;

                                          } else {

                                                var t:Timer  = new Timer(duration/(nEnd-nStart),nEnd-nStart);

                                       

                                      t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f2(e,nEnd,tf)});

                                                 t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));

                                                t.start();

                                          }

                                      }

                                      function   f2(e:TimerEvent,nEnd:int,tf:TextField){

                                          tf.text = nEnd-e.target.currentCount;

                                      }

                                       

                                      function   countDown1F(nStart:int,nEnd:int,duration:uint,tf:TextField) {

                                          if   (nStart>=nEnd) {

                                              return null;

                                          } else {

                                               var t:Timer  = new Timer(duration/(nEnd-nStart),nEnd-nStart);

                                       

                                      t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f1(e,nEnd,tf)});

                                                t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));

                                                t.start();

                                          }

                                      }

                                      function   f1(e:TimerEvent,nEnd:int,tf:TextField){

                                          tf.text = formatF(  (nEnd-e.target.currentCount));

                                      }

                                       

                                      function formatF(n:int):String {

                                      var min:int = Math.floor(n/60);

                                      var sec:int = n-min*60;

                                      var a:Array = ;

                                      for (var i:uint=0; i<a.length; i++) {

                                        while (a[i].length<2) {

                                         a[i]="0"+a[i];

                                        }

                                      }

                                      return a[0] + ":" + a[1];

                                      }

                                       

                                       

                                      *there were 4 errors 2 at line 15:"incompatible ovverride." "duplicate

                                      function definition."*

                                      the same 2 errors at line 30.

                                       

                                      any idea?

                                      thanks.

                                      • 16. Re: create a countdown
                                        kglad Adobe Community Professional & MVP

                                        you must have some code in you fla, in addition to the last snippet i suggested.

                                        • 17. Re: create a countdown
                                          netartdesign Level 1

                                          yes i do have another script at the last frame of a play button:

                                           

                                          stop();

                                          playbutton.addEventListener(MouseEvent.MOUSE_DOWN,playclip);

                                          //Setting the MOUSE_DOWN event to the startbutton, and when that event is

                                          triggered, it starts the playclip function.

                                          function playclip(e:MouseEvent):void {

                                          play();

                                          }

                                           

                                          is that make any difference?

                                          • 18. Re: create a countdown
                                            kglad Adobe Community Professional & MVP

                                            no, that's not the problem.  you have left-over code sitting somewhere.

                                             

                                            here's a working example:  www.kglad.com/Files/forums/Untitled-3.fla

                                            • 19. Re: create a countdown
                                              netartdesign Level 1

                                              yap your works bueatiful . i was looking up for other scripts in my fla.

                                              except of what i end you there are only stop actions and the action of the

                                              changing number that you gave me last time:

                                               

                                              a1.numbers.text="8.99".toString();

                                              a2.numbers.text="21.01".toString();

                                              a3.numbers.text="20.01".toString();

                                              a4.numbers.text="19.98".toString();

                                              a5.numbers.text="24.01".toString();

                                              a6.numbers.text ="14.63".toString();

                                              a7.numbers.text="27.27".toString();

                                              a8.numbers.text="27.30".toString();

                                              a9.numbers.text="28.45".toString();

                                              a10.numbers.text ="28.63".toString();

                                              b1.numbers.text="25.50".toString();

                                              b2.numbers.text="27.56".toString();

                                              b3.numbers.text="15.18".toString();

                                              b4.numbers.text="27.61".toString();

                                              b5.numbers.text="28.50".toString();

                                              b6.numbers.text="8.99".toString();

                                              b7.numbers.text="10.52".toString();

                                              b8.numbers.text="30.00".toString();

                                              b9.numbers.text="27.99".toString();

                                              b10.numbers.text="27.41".toString();

                                              c1.numbers.text="20.13".toString();

                                              c2.numbers.text="10.09".toString();

                                              c3.numbers.text="28.50".toString();

                                              c4.numbers.text="22.51".toString();

                                              c5.numbers.text="30.00".toString();

                                              c6.numbers.text="27.55".toString();

                                              c7.numbers.text="20.05".toString();

                                              c8.numbers.text="21.01".toString();

                                              c9.numbers.text="29.95".toString();

                                              c10.numbers.text="29.61".toString();

                                              d1.numbers.text="29.41".toString();

                                              d2.numbers.text="22.52".toString();

                                              d3.numbers.text="29.61".toString();

                                              d4.numbers.text="14.30".toString();

                                              d5.numbers.text="24.00".toString();

                                              d6.numbers.text="28.51".toString();

                                              d7.numbers.text="24.01".toString();

                                              d8.numbers.text="29.06".toString();

                                              d9.numbers.text="29.14".toString();

                                              d10.numbers.text="28.01".toString();

                                              e1.numbers.text="26.11".toString();

                                              e2.numbers.text="27.61".toString();

                                              e3.numbers.text="19.98".toString();

                                              e4.numbers.text="29.14".toString();

                                              e5.numbers.text="27.72".toString();

                                              e6.numbers.text="29.06".toString();

                                              e7.numbers.text="12.54".toString();

                                              e8.numbers.text="24.01".toString();

                                              e9.numbers.text="29.41".toString();

                                              e10.numbers.text="9.99".toString();

                                              f1.numbers.text="20.00".toString();

                                              f2.numbers.text="13.22".toString();

                                              f3.numbers.text="27.30".toString();

                                              f4.numbers.text="21.96".toString();

                                              f5.numbers.text="27.27".toString();

                                              f6.numbers.text="27.41".toString();

                                              f7.numbers.text="27.50".toString();

                                              f8.numbers.text="28.10".toString();

                                              f9.numbers.text="29.95".toString();

                                              f10.numbers.text="27.55".toString();

                                              g1.numbers.text="28.99".toString();

                                              g2.numbers.text="20.00".toString();

                                              g3.numbers.text="25.50".toString();

                                              g4.numbers.text="27.72".toString();

                                              g5.numbers.text="28.95".toString();

                                              g6.numbers.text="28.01".toString();

                                              g7.numbers.text="20.05".toString();

                                              g8.numbers.text="27.95".toString();

                                              g9.numbers.text="22.00".toString();

                                              g10.numbers.text="28.10".toString();

                                              h1.numbers.text="20.11".toString();

                                              h2.numbers.text="22.52".toString();

                                              h3.numbers.text="27.95".toString();

                                              h4.numbers.text="28.11".toString();

                                              h5.numbers.text="29.99".toString();

                                              h6.numbers.text="27.97".toString();

                                              h7.numbers.text="28.95".toString();

                                              h8.numbers.text="27.98".toString();

                                              h9.numbers.text="20.13".toString();

                                              h10.numbers.text="28.99".toString();

                                              i1.numbers.text="27.97".toString();

                                              i2.numbers.text="28.11".toString();

                                              i3.numbers.text="29.99".toString();

                                              i4.numbers.text="26.11".toString();

                                              i5.numbers.text="27.99".toString();

                                              i6.numbers.text="27.56".toString();

                                              i7.numbers.text="21.96".toString();

                                              i8.numbers.text="28.51".toString();

                                              i9.numbers.text="28.45".toString();

                                              i10.numbers.text="22.00".toString();

                                              j1.numbers.text="27.50".toString();

                                              j2.numbers.text="27.98".toString();

                                              j3.numbers.text="27.39".toString();

                                              j4.numbers.text="20.01".toString();

                                              j5.numbers.text="9.99".toString();

                                              j6.numbers.text="25.50".toString();

                                              j7.numbers.text="20.11".toString();

                                              j8.numbers.text="27.41".toString();

                                              j9.numbers.text="22.51".toString();

                                              j10.numbers.text="24.00".toString();

                                               

                                              which i dont think this is why i still have the problem. any other reasson

                                              that can cause that?

                                              thanks.

                                              • 20. Re: create a countdown
                                                kglad Adobe Community Professional & MVP

                                                either start over with a new fla or remove all the code related to the countdown from your current fla.

                                                 

                                                if you start over, start with the fla you downloaded.

                                                 

                                                if you remove the old code, use movie explorer to seach for countdown in your actionscript looking in all objects.  you should find none or you didn't remove everything.  then copy the code from the fla you downloaded to your fla.

                                                • 21. Re: create a countdown
                                                  BLAAT

                                                  I made an example in AS3 for Flash CC. You can download an example on my site. Go to http://www.thingsiwish.nl/adobe-flash-countdown-banner/

                                                   

                                                  Hope it works.

                                                  • 22. Re: create a countdown
                                                    kazemb33155285

                                                    Hey I have the same issue

                                                     

                                                    Can you possibly upload that fla file so I could also use it to see if iI can fix my issue

                                                     

                                                    Please