Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Flash Countdown Issue

New Here ,
Dec 22, 2015 Dec 22, 2015

Can anybody help with my Flash countdown issue?  Below is the script, it works but I want specific spacing between the days/hours/minutes/seconds.  Even though I set the text up with the correct spacing, the exported file doesn't carry it. 

this.onEnterFrame = function() {   var today:Date = new Date(); var currentYear = today.getFullYear(); var currentTime = today.getTime(); var targetDate:Date = new Date(2016,0,31); var targetTime = targetDate.getTime();   var timeLeft = targetTime - currentTime; var sec = Math.floor(timeLeft/1000); var min = Math.floor(sec/60); var hrs = Math.floor(min/60); var days = Math.floor(hrs/24); sec = String(sec % 60); if (sec.length < 2) {   sec = "0" + sec; } min = String(min % 60); if (min.length < 2) {   min = "0" + min; } hrs = String(hrs % 24); if (hrs.length < 2) {   hrs = "0" + hrs; } days = String(days); var counter:String = days + ":" + hrs + ":" + min + ":" + sec; time_txt.text = counter; }

TOPICS
ActionScript
854
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 22, 2015 Dec 22, 2015

use 4 different textfields (eg, days_tf, hours_tf etc):  one each for days, hours, min and sec.  position them in the obvious way and change that time_text.text line to:

days_tf.text = days;

hours_tf.text=hours;

min_tf.text=min

sec_tf.text=sec;

Translate
Community Expert ,
Dec 22, 2015 Dec 22, 2015

what spacing are you failing to see that you expect?

p.s. formatting your code so it's legible can be helpful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2015 Dec 22, 2015

So I have a background I want the text to stay within (see picture below) and the text doesn't keep the spacing.  Instead it reverts to 00:00:00:00 all next to one another.  Sorry about the coding, the formatted version is at the bottom.

Countdown.jpg

this.onEnterFrame = function()

{

  var today:Date = new Date();

  var currentYear = today.getFullYear();

  var currentTime = today.getTime();

  var targetDate:Date = new Date(2016,0,31);

  var targetTime = targetDate.getTime();

  var timeLeft = targetTime - currentTime;

  var sec = Math.floor(timeLeft/1000);

  var min = Math.floor(sec/60);

  var hours = Math.floor(min/60);

  var days = Math.floor(hours/24);

  sec = String(sec % 60);

  if(sec.length < 2){

  sec = "0" + sec;

  }

  min = String(min % 60);

  if(min.length < 2){

  min = "0" + min;

  }

  hours = String(hours % 24);

  if(hours.length < 2){

  hours = "0" + hours;

  }

  days = String(days);

  if(timeLeft > 0 ){

  var counter:String = days + ":" + hours + ":" + min + ":" + sec;

  time_txt.text = counter;

  }else{

  trace("TIME'S UP");

        var newTime:String = "00:00:00:00";

        time_txt.text = newTime;

        delete (this.onEnterFrame);

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2015 Dec 22, 2015

use 4 different textfields (eg, days_tf, hours_tf etc):  one each for days, hours, min and sec.  position them in the obvious way and change that time_text.text line to:

days_tf.text = days;

hours_tf.text=hours;

min_tf.text=min

sec_tf.text=sec;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2015 Dec 22, 2015

thanks, that fixed the issue!  I appreciate the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2015 Dec 22, 2015

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2015 Dec 22, 2015

‌just marked it as answered. Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 23, 2015 Dec 23, 2015

you're welcome (and happy holidays!)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 23, 2015 Dec 23, 2015
LATEST

happy holidays!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines