A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 38

Thread: Countdown Timer help, please? :)

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    11

    Countdown Timer help, please? :)

    Hello!!

    I'm trying to create a countdown widget that counts down to the release date of a product and once the date gets here, the timer gets replaced with text and links that say something along the lines of "available now! buy here: purchase link".

    I am posting the AS code and the error I'm getting. Any help you guys can give would be greatly appreciated!! Thanks.


    Alright here is the action script now:

    Code:
    import flash.events.Event;
    
    
    var targetDate:Date = new Date(2014, 3, 29, 0,0,0);
    
    addEventListener(Event.ENTER_FRAME, loop);
    
    function loop(e:Event):void
    {
        var nowDate:Date = new Date();
        var ms:Number = targetDate.getTime() - nowDate.getTime();
    
        if(ms<=0)
        {
            removeEventListener(Event.ENTER_FRAME, loop);
          gotoAndStop(2);
    	  return;
    	 
        }
        else
        {
            var sec:Number = Math.floor(ms/1000);
            var min:Number = Math.floor(sec/60);
            var hr:Number = Math.floor(min/60);
            var day:Number = Math.floor(hr/24);
    
            sec = sec % 60;
            min = min % 60;
            hr = hr % 24;
    
            daytxt.text = day.toString();
            hrtxt.text = (hr < 10) ? "0" + hr.toString():hr.toString();
            mintxt.text = (min < 10) ? "0" + min.toString():min.toString();
            sectxt.text = (sec < 10) ? "0" + sec.toString():sec.toString();
        }
    }

    and the error I am getting:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at sweet_fla::MainTimeline/loop()[sweet_fla.MainTimeline::frame1:31]
    Any help you can give?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You probably forgot to name something properly, one of the textFields perhaps.

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Yeah. I copied/pasted your script, and put 4 textfields with names "hrtxt, sectxt, daytxt and mintxt" and it's working like a charm

    It is like fruitbeard said, some textfield is named wrong.


    P.S: Don't forget to embbed the fonts
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    ????

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    11
    ok here's some more info:

    Here's some more info.

    The error is saying:
    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at sweet_fla::MainTimeline/loop()[sweet_fla.MainTimeline::frame1:31]
    That's saying Frame 1, Line 31 in the actionscript right?

    Well this is what line 31 is:
    Code:
    daytxt.text = day.toString();
    and here is all of the actionscript:

    Code:
    import flash.events.Event;
    
    
    var targetDate:Date = new Date(2014, 3, 29, 0,0,0);
    
    addEventListener(Event.ENTER_FRAME, loop);
    
    function loop(e:Event):void
    {
        var nowDate:Date = new Date();
        var ms:Number = targetDate.getTime() - nowDate.getTime();
    
        if(ms<=0)
        {
            removeEventListener(Event.ENTER_FRAME, loop);
          gotoAndStop(2);
          return;
         
        }
        else
        {
            var sec:Number = Math.floor(ms/1000);
            var min:Number = Math.floor(sec/60);
            var hr:Number = Math.floor(min/60);
            var day:Number = Math.floor(hr/24);
    
            sec = sec % 60;
            min = min % 60;
            hr = hr % 24;
    
            daytxt.text = day.toString();
            hrtxt.text = (hr < 10) ? "0" + hr.toString():hr.toString();
            mintxt.text = (min < 10) ? "0" + min.toString():min.toString();
            sectxt.text = (sec < 10) ? "0" + sec.toString():sec.toString();
        }
    }
    And all of my text fields are named what they're defined in the AS, fonts are embedded and frame 2 exists.

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I think you have your textfields inside a movieclip, or in another frame.

    Here is working great your script, i placed 4 movieclips named hrtxt, sectxt, mintxt and daytxt, on stage, out of any movieclip.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    11
    I'm not sure of what you just said. Hah. But here is the FLA file if anyone wants to look at it?

    https://drive.google.com/file/d/0B6r...it?usp=sharing

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I downloaded your FLA already, i repeat.

    And here is working PERFECTLY. Check the version of flash player you are testing the movie. Check that it is set to Actionscript 3, and not Actionscript2.
    Check that your text boxes are on the stage, and not inside a movieclip.
    Try making a new .fla project and copy/pasting your textfields there, and your script.

    I don't know why you are having issues.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  9. #9
    Junior Member
    Join Date
    Feb 2014
    Posts
    11
    I tried making a new .fla like you suggested, it didn't work. Sorry I'm prettynew to flash so I'm not sure how to check to see if my text boxes are on the stage and not inside a movie clip? I mean, I see them on the stage? lol. Thanks!

  10. #10
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Follow the tutorial of my last post.
    Last edited by angelhdz; 02-08-2014 at 11:54 PM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  11. #11
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    You can follow this other tutorial, without using classes:

    http://www.riacodes.com/flash/new-ye...down-with-as3/
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    It's because you are using more than one frame without a stop and the number textfields disappear every 1 frame, so use a stop(); at the start of your code on frame 1.

  13. #13
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Lol fruitbeard, are you serious my friend? That was the issue? Hahahah sorry for laughing, it's funny (not being sarcastic just in case hehe).

    I got entertained with her/his script trying to fix some things for getting the date countdown to work, but then i said "bah" and i found
    a working tutorial for her/him, and now i'm playing with that tutorial. (by the way, i'm busy working with Datagrid in AS3, XML, and SQLITE)

    People have to be careful with frames, because most of the time, frames are the reason of their issues.

    ¡Saludos!
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  14. #14
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Their script works just fine and doesn't need fixing, just the stop(); being added, we have all overlooked such simple things before, neither of us are masters yet and you have made some major errors before Angel, still do from what I read here.

    Ciao

  15. #15
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I said that i never made these mistakes? Let me read. No i didn't say that. It's obvious that everyone make mistakes, even you, even professionals programmers, so no need to boast here. And yes, it had a bug, I put a date countdown yesterday (february 8) for 2014, february 9, and the day said "28" (my computer date and hour is ok). It should say "0" because 0 days left for february 9 to come, only a few hours/minutes left.
    I'm just advising our friend, to be careful from now on, with her/his frames because most of the time is the reason of the conflicts.

    And this is kind of "obvious" because the first thing you learn when you start using flash, is to play/stop the timeline. So if you don't want a movieclip, or script, stop working, you have to be carefull where you put yourscripts, and put the corresponding "stop();" function to stop on a frame and not
    keep running/looping.

    Have a nice day, both of you.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  16. #16
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Their code works fine Angel, you put the wrong date in to test for February.

    when referring to this line of code:
    PHP Code:
    var targetDate:Date = new Date(20143290,0,0); 
    the target date in that line is {29th April 2014} ^^^

    those numbers inside the brackets read: new Date(year, month, day, hours, seconds, minutes) *ms if you wanted them too.

    the Month part starts at 0 like arrays do, so 0 = January, 1 = February, 2 = March, 11 = December.

    Enjoy xx

    Perhaps it was a simple mistake like leaving out a stop(); command somewhere...
    Last edited by fruitbeard; 02-09-2014 at 12:56 PM.

  17. #17
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok, my bad. I forgot about the fact that actionscript is 0 based. So January would be 0, february 1, march 2 and so on.

    You see? Nobody is perfect here i'm sure you make a lot of mistakes, before posting something here. Don't be ashamed of that


    P.S: I've never ever implied here that i'm an advanced programmer. You and some other guy are the only ones that act always like if you ALL-KNOWING. I'm here to learn, and to put in practice what I've learned. If you can comment whatever you want, I can as well.

    I'm out! Ya fue suficiente por hoy , by the way your chat is always offline xD, i want to make a chat like yours
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  18. #18
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    No not all knowing, never ever claimed so, you just feel this way, you are doing it again like in so many threads, making it a chat feature for YOU.
    perhaps you just want to make your post number larger with all this ranting, quality not quantity so they say.

  19. #19
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    hahahaha you make my laugh out loud. Are you reflecting yourself? I think it's you the one that celebrated once, the fact of reaching "x" numbers of posts. I'm as this forum member here as your are, so, when a new thread is posted, I check it up, and if I can help, I help. Period. Helping others, doesn't mean that you have to be ADVANCED or PERFECT. Helping means that you take a little of your time, to seek for a solution, with you already gained knowledge, or with your ability of researching on the web. At least i'm always trying here helping others, not critizicing scripts as you always do n:

    P.S: The fact that you already learned the best way of doing stuff, doesn't mean that there are not other ways of achieving it. You learned? Then let me learn in peace. Want to teach me? Then do it , but not critizice me or make fool of my scripts. Want to show the world how advanced you are? Then have the patience of teaching with love, and not with arrogance. And the same way you are always following threads and posts and commenting whatever you want, i can as well. I have the right. Don't want to keep reading these type of comments from me? Then don't critizice or undervalue my attempts of coding.

    I feel really bad when you critizice me or make me feel like my stuff is a crap, but i don't think anyone here cares about that. So, as you said before, i'f i'm not wrong, this is a forum, people comes and goes, so you comment about me? Then I will comment about you.

    Peace out
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  20. #20
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You are still doing it angel, start a new thread about your problems with coding and other peoples comments please, this is somebodies thread, like somebody else said, its not all about YOU, its about people getting correct answers.

    We are all here to learn too, yet again, not just YOU.

    It's great that you try to help, like we all do, however getting something wrong is not the way to do it and making fun of somebody because they missed a stop(); command out is the pits, then you go do it yourself, but I think you didn't make a simple mistake, you just did not know.

    Have a great day xx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center