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 7, 2020

Excellent 

 

I've used it

 

Furthermore

I have a frame. It has 3 buttons which have functions

 

I wanna make a copy of the same frame with the same buttons

 

But i want this duplicate frame to get all its functions ( including its timer ) from the original

 

Is there a way of getting frsmelabels to call functions from other frames ?

 

 

Or will I just have to work with each button timer individually and make them all call its own functions from their originals


again, all these anonomous functions exist in all frames on the same timeline.  if you're calling from a different timeline, you would need to reference the timeline where the functions are defined but if you're calling from the same timeline you call just by using the function reference (eg, countUp1F).

 

if the same 3 buttons from the first frame that executes don't continue to exist where you want to define the 2nd group of 3 buttons, recreate (eg, copy and paste) the buttons but give them different instance names and define their listeners.  they can call the same listener function as the first group as explained in the last two messages.