# Countdown from external .txt file

**URL:** <https://forum.kirupa.com/t/countdown-from-external-txt-file/111318>\
**Category:** Uncategorized\
**Created:** [May 25, 2004, 8:42pm UTC](https://forum.kirupa.com/t/countdown-from-external-txt-file/111318 "2004-05-25T20:42:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mderusha](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mderusha](https://forum.kirupa.com/u/mderusha)\
**Post date:** [May 25, 2004, 8:42pm UTC](https://forum.kirupa.com/t/countdown-from-external-txt-file/111318/1 "2004-05-25T20:42:14Z")

</div>

I have a juicy bit of code (thanks to Senocular at Kirupa) that goes something like this: (comments removed to save space)

```auto
stop();

currentDate = new Date();
thisYear = currentDate.getFullYear();

eventDate = new Date(thisYear, 11, 25);
eventMillisecs = eventDate.getTime();

counter.onEnterFrame = function(){
 currentDate = new Date();
 currentMillisecs = currentDate.getTime();
 this.msecs = eventMillisecs - currentMillisecs;
 
 if (this.msecs <= 0){
  play();
  return;
 }
 
 this.secs = Math.floor(this.msecs/1000); // 1000 milliseconds make a second
 this.mins = Math.floor(this.secs/60); // 60 seconds make a minute
 this.hours = Math.floor(this.mins/60); // 60 minutes make a hour
 this.days = Math.floor(this.hours/24); // 24 hours make a second
 
 this.msecs = string(this.msecs % 1000);
 this.secs = string(this.secs % 60);
 this.mins = string(this.mins % 60);
 this.hours = string(this.hours % 24);
 this.days = string(this.days);
 
 while (this.msecs.length < 3) this.msecs = "0" + this.msecs;
 if (this.secs.length < 2) this.secs = "0" + this.secs;
 if (this.mins.length < 2) this.mins = "0" + this.mins;
 if (this.hours.length < 2) this.hours = "0" + this.hours;
 while (this.days.length < 3) this.days = "0" + this.days;

 for(movie in this){
  if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);
 }
};

MovieClip.prototype.evaluateFrameFrom = function(variableClip){
 var nameArray = this._name.split("_");
 var numberSet = variableClip[nameArray[0]];
 var character = number(nameArray[1]);
 var frame = 1 + number(numberSet.charAt(character));
 if (this._currentframe != frame) this.gotoAndStop(frame);
};

```

my problem is that I want to supply the end date by using variables from a .txt file

this is my “solution” (that does not work)

```auto
stop();

loadVariablesNum("count.txt", 0);

thisMonth = thisMonthDate;
thisDay = thisDayDate;
thisHour = thisHourTime;
thisMinute = thisMinuteTime;

currentDate = new Date();
thisYear = currentDate.getFullYear();

eventDate = new Date(thisYear, thisMonth, thisDay, thisHour, thisMinute);
eventMillisecs = eventDate.getTime();

counter.onEnterFrame = function(){
 currentDate = new Date();
 currentMillisecs = currentDate.getTime();
 
 this.msecs = eventMillisecs - currentMillisecs;
 
 if (this.msecs <= 0){
  play();
  return;
 }
 
 this.secs = Math.floor(this.msecs/1000); // 1000 milliseconds make a second
 this.mins = Math.floor(this.secs/60); // 60 seconds make a minute
 this.hours = Math.floor(this.mins/60); // 60 minutes make a hour
 this.days = Math.floor(this.hours/24); // 24 hours make a second
 
 this.msecs = string(this.msecs % 1000);
 this.secs = string(this.secs % 60);
 this.mins = string(this.mins % 60);
 this.hours = string(this.hours % 24);
 this.days = string(this.days);
 
 while (this.msecs.length < 3) this.msecs = "0" + this.msecs;
 if (this.secs.length < 2) this.secs = "0" + this.secs;
 if (this.mins.length < 2) this.mins = "0" + this.mins;
 if (this.hours.length < 2) this.hours = "0" + this.hours;
 while (this.days.length < 3) this.days = "0" + this.days;

 for(movie in this){
  if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);
 }
};

MovieClip.prototype.evaluateFrameFrom = function(variableClip){
 var nameArray = this._name.split("_");
 var numberSet = variableClip[nameArray[0]];
 var character = number(nameArray[1]);
 var frame = 1 + number(numberSet.charAt(character));
 if (this._currentframe != frame) this.gotoAndStop(frame);
};

```

If i put numbers in place of “thisMonthDate” etc, it works just fine.

my code in the .txt file goes like this:

```auto
thisMonthDate=8
&thisDayDate=26
&thisHourTime=15
&thisMinuteTime=29

```

help this poor noob.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2004, 8:56pm UTC](https://forum.kirupa.com/t/countdown-from-external-txt-file/111318/2 "2004-05-25T20:56:32Z")

</div>

figured it out…

I had the syntax wrong in the .txt file. It should be

```auto
&thisMonthDate=4&
&thisDayDate=26&
&thisHourTime=15&
&thisMinuteTime=29&

```

:

not having the ampersand at the end of each line was messing up the AS.

thx all for reading.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 25, 2004, 9:00pm UTC](https://forum.kirupa.com/t/countdown-from-external-txt-file/111318/3 "2004-05-25T21:00:14Z")

</div>

thanks for posting the solution! :thumb:  
I hate it when you see posts like “never mind I fixed it” but no hints on how. Ⓜ \<– _edit_ what is this? what happenned to the mad smiley with the heat waves coming out of his head? Did it get replaced? :huh:
