Skip to main content
Known Participant
July 4, 2019
Answered

Please help me add a gotoandstop function to the end of mytimer

  • July 4, 2019
  • 2 replies
  • 4444 views

Please help me create a go to and stop (Frame)

function to the end of my timer!?

I'm struggling - tried everything

My script is below

countDown1F(00,50,50000,tf1);

function countDown2F(nStart:int,nEnd:int,duration:uint,tf:TextField) {

  if (nStart>=nEnd) {

  return null;

  } else {

  var t:Timer = new Timer(duration/(nEnd-nStart),nEnd-nStart);

t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f2(e,nEnd,tf)});

  t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));

  t.start();

  }

}

function f2(e:TimerEvent,nEnd:int,tf:TextField){

 

}

function countDown1F(nStart:int,nEnd:int,duration:uint,tf:TextField) {

  if (nStart>=nEnd) {

  return null;

  } else {

  var t:Timer = new Timer(duration/(nEnd-nStart),nEnd-nStart);

t.addEventListener(TimerEvent.TIMER,function(e:TimerEvent){f1(e,nEnd,tf)});

  t.dispatchEvent(new TimerEvent(TimerEvent.TIMER));

  t.start();

  }

}

function f1(e:TimerEvent,nEnd:int,tf:TextField){

  tf.text = formatF( (nEnd-e.target.currentCount));

}

function formatF(n:int):String {

var min:int = Math.floor(n/60);

var sec:int = n-min*60;

var a:Array = [min.toString(),sec.toString()];

for (var i:uint=0; i<a.length; i++) {

  while (a.length<2) {

  a="0"+a;

  }

}

return a[0] + ":" + a[1];

}

This topic has been closed for replies.
Correct answer kglad

I mean how do I create a button that can reset that same counter back to zero*


yourbutton.addEventListener("MouseEvent.CLICK,f);

 

function f(e:MouseEvent):void{

counter=0;

}

2 replies

Reachil
Participant
February 13, 2023

what's the trace output after 2 frame visits

kglad
Community Expert
Community Expert
July 5, 2019

var t:Timer;

var tf:TextField;

var nend:int;

countDown1F(00,50,50000,tf1);

function countDown1F(nstart:int,nend:int,duration:int,_tf:TextField):void{

if(nstart<nend){

tf=_tf;

t=new Timer(duration/(nend-nstart),nend-nstart);

t.addEventListener(TimerEvent.TIMER,timerF);

t.start();

}

}

function timerF(e:TimerEvent):void{

tf.text=formatF(nend-e.targer.currentCount);

if(e.currentCount==e.repeatCount){

gotoAndStop(wherever);  // assign wherever

}

}

function formatF(n:int):String {

var min:int = Math.floor(n/60);

var sec:int = n-min*60;

var a:Array = [min.toString(),sec.toString()];

for (var i:uint=0; i<a.length; i++) {

  while (a.length<2) {

  a="0"+a;

  }

}

return a[0] + ":" + a[1];

}

kazembAuthor
Known Participant
July 5, 2019

Thanks bro!! !

kglad
Community Expert
Community Expert
February 6, 2020

Or even possibly making a whole frame inherit the properties of all the coding from another frame ? 

 

So effectively you have dupilcate frames but they use the same coding for the assests on them 

 

Is this possible?


anonymous functions (eg, all the ones used in this thread) exist on all frames.  they don't need to be and should not be repeated.

 

what doesn't necessarily exist on all frames are objects on stage (eg, buttons and textfields etc).  if you want two buttons to call the same function, use:

 

btn1.addEventListener(MouseEvent.CLICK, f);

btn2.addEventListener(MouseEvent.CLICK, f);

 

/////////////////////////////////////////////////////////////////////////////////////////////////

if you wanted btn1 and btn2 to call the countup code you could use:

 

function f(e:MouseEvent){

countUp1F(00, 50, 50000, tf1);

}

///////////////////////////////////////////////////////////////////////////////////////////////////

 

if you wanted btn1 and btn2 to use different parameters to call the countup code, have them call different functions:

 

 

btn1.addEventListener(MouseEvent.CLICK, f1);

btn2.addEventListener(MouseEvent.CLICK, f2);

 

function f1(e:MouseEvent){

countUp1F(00, 50, 50000, tf1);

}

 

function f2(e:MouseEvent){

countUp1F(00, 50, 50000, tf2);

}