A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: I made a countdown, but how can i change the colors of the digits in intervals?

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2

    I made a countdown, but how can i change the colors of the digits in intervals?

    Hi there. I have been tasked with creating a countdown for a splash page. I am not too familiar with flash so I took a couple online lessons and found some great sources to help me come up with a countdown which you can see here. http://www.swfcabin.com/open/1376959235


    Now, my colleauge asked if it is possible to have the numbers turn red on each circle, which i was able to accomplish here: http://www.swfcabin.com/open/1376958743


    If you notice, the countdown no longer works on on the second example and I keep getting an error message and I honestly have no idea what's going on. I tried playing with the timeline with no success and my capacity with ActionScript 3 is beginner at best. I was actually able to find an online tutorial that gave me some code to use and i just played around with it for my use.


    Here is the error message i get:


    TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at BirthdayCountdown_fla::MainTimeline/loop()




    Here is the code I am using:


    var targetDateate = new Date(2014, 7, 8, 15);

    addEventListener(Event.ENTER_FRAME, loop);

    function loop(e:Event):void
    {
    var nowDateate = new Date();
    var ms:Number = targetDate.getTime() - nowDate.getTime();
    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 here is a screenshot of my timeline.

    http://imgur.com/A6xMFx3

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

    This might help you out, although I'm not sure how often you wanted the text to alternate colour
    PHP Code:
    var targetDate = new Date(2014,7,8,15);

    addEventListener(Event.ENTER_FRAMEloop);

    function 
    loop(e:Event):void
    {
        var 
    nowDate = new Date();
        var 
    ms:Number targetDate.getTime() - nowDate.getTime();
        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();

    }
    addEventListener(Event.ENTER_FRAMEloop);

    var 
    Inc:Number 0;
    var 
    TextArray:Array = new Array("sectxt","mintxt","hrtxt","daytxt");

    function 
    Colour():void
    {
        for (var 
    j:Number 0TextArray.lengthj++)
        {
            
    this[TextArray[j]].textColor 0xFFFFFF;
        }
        
    this[TextArray[Inc]].textColor 0xFF0000;
        
    Inc++;
        if (
    Inc >= TextArray.length)
        {
            
    Inc 0;
        }
    }
    setInterval(Colour,1000); 
    you don't need to have all those extra frames, you can have it all one one frame (layers excluded).

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    2

    Thumbs up

    Quote Originally Posted by fruitbeard View Post
    Hi,

    This might help you out, although I'm not sure how often you wanted the text to alternate colour
    PHP Code:
    var targetDate = new Date(2014,7,8,15);

    addEventListener(Event.ENTER_FRAMEloop);

    function 
    loop(e:Event):void
    {
        var 
    nowDate = new Date();
        var 
    ms:Number targetDate.getTime() - nowDate.getTime();
        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();

    }
    addEventListener(Event.ENTER_FRAMEloop);

    var 
    Inc:Number 0;
    var 
    TextArray:Array = new Array("sectxt","mintxt","hrtxt","daytxt");

    function 
    Colour():void
    {
        for (var 
    j:Number 0TextArray.lengthj++)
        {
            
    this[TextArray[j]].textColor 0xFFFFFF;
        }
        
    this[TextArray[Inc]].textColor 0xFF0000;
        
    Inc++;
        if (
    Inc >= TextArray.length)
        {
            
    Inc 0;
        }
    }
    setInterval(Colour,1000); 
    you don't need to have all those extra frames, you can have it all one one frame (layers excluded).
    Thank you fruitbeard. This helped me IMMENSELY. I clicked on your signature line to make a donation. It's not much, but you can count on more coming in as I am sure I will run into other issues in the future. I sincerely thank you for your help!!!!

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

    Thank you kindly sir, was very unexpected, I will be glad to assist you as and when I can.

    Fruit

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