Skip to main content
Participant
May 6, 2009
Answered

Actionscript clock function problem

  • May 6, 2009
  • 2 replies
  • 866 views

I have created a clock within flash but when I place it as an button selected object in a timeline it does not function, can anyone help me?

Thanks in anticipation!

You can view swf file here.

My actionscript is as follows:

time_btn.onRelease = function() {
gotoAndPlay("rolex_ani");

var hours = timenow.getHours();
var minutes = timenow.getMinutes();
var seconds = timenow.getSeconds();
var milliseconds = timenow.getMilliseconds();
var date:Number=timenow.getDate();
var day:String=days[timenow.getDay()];
var month:String=months[timenow.getMonth()];
    var days:Array=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months:Array=["January", "February", "March", "April", "May", "June", "July", "August",
       "September", "October", "November", "December"];

timenow = new Date();
day_txt.text =day;
date_txt.text =date;
month_txt.text=month;
   
hours_mc._rotation = (hours*30) + (minutes/2);   
minutes_mc._rotation = (6 * minutes)+(0.1 * seconds);  
seconds_mc._rotation = (0.006 * milliseconds)+(6 * seconds);

}

This topic has been closed for replies.
Correct answer kglad

try the code below.  and you should delete the onEnterFrame loop when it's not needed.


time_btn.onRelease = function() {
gotoAndStop("rolex_ani");
this.onEnterFrame=function(){

timenow = new Date()

var hours = timenow.getHours();
var minutes = timenow.getMinutes();
var seconds = timenow.getSeconds();
var milliseconds = timenow.getMilliseconds();
var date:Number=timenow.getDate();
var day:String=days[timenow.getDay()];
var month:String=months[timenow.getMonth()];
    var days:Array=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months:Array=["January", "February", "March", "April", "May", "June", "July", "August",
       "September", "October", "November", "December"];

day_txt.text =day;
date_txt.text =date;
month_txt.text=month;
   
hours_mc._rotation = (hours*30) + (minutes/2);   
minutes_mc._rotation = (6 * minutes)+(0.1 * seconds);  
seconds_mc._rotation = (0.006 * milliseconds)+(6 * seconds);

}

}

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 6, 2009

try the code below.  and you should delete the onEnterFrame loop when it's not needed.


time_btn.onRelease = function() {
gotoAndStop("rolex_ani");
this.onEnterFrame=function(){

timenow = new Date()

var hours = timenow.getHours();
var minutes = timenow.getMinutes();
var seconds = timenow.getSeconds();
var milliseconds = timenow.getMilliseconds();
var date:Number=timenow.getDate();
var day:String=days[timenow.getDay()];
var month:String=months[timenow.getMonth()];
    var days:Array=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months:Array=["January", "February", "March", "April", "May", "June", "July", "August",
       "September", "October", "November", "December"];

day_txt.text =day;
date_txt.text =date;
month_txt.text=month;
   
hours_mc._rotation = (hours*30) + (minutes/2);   
minutes_mc._rotation = (6 * minutes)+(0.1 * seconds);  
seconds_mc._rotation = (0.006 * milliseconds)+(6 * seconds);

}

}

Participant
May 7, 2009

Did not work at first, I had already tried the same piece of code, but you made me think about it again.

I removed the "thisonEnterframe" and replaced it with the label name of the frame "rolex_ani.onEnterFrame" and we are up and running!

Strangely I still have a problem with the day and month panels returning an "undefined" error message, but that should be easier to find.

Thanks buddy for leading me out of a darkened place!

kglad
Community Expert
Community Expert
May 7, 2009

you're welcome.

kglad
Community Expert
Community Expert
May 6, 2009

timenow should be instantiated before you try and use its methods.  move the

timenow=new Date();

line just below your goto function.

Participant
May 6, 2009

Thanks for the suggestion, I have moved the line but it has not made any difference.

If you click the timepiece button several times you will see that the time function is working but the screen moves on to the next frame. If I put a "stop" function in, the clock function will not refresh.

However, the script functions perfectly as a standalone, just not within my "label" selected timeline.

You can see the standalone swf here

kglad
Community Expert
Community Expert
May 6, 2009

whoa, is that supposed to be a gotoAndStop()?