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!! !

kazembAuthor
Known Participant
December 8, 2022

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.


HI Kglad - im trying to make this counter - that counts up when ever the timeline hits a specific frame ( so with a mouse event)  it just counts up when ever the time line hits a certain frame 

 

My counter :

 

Add.addEventListener ( MouseEvent.CLICK, addone);

Var counts = 0;

 

Count.text = Counts1;

function addone ( event:Event) {

counts1 ++ ;

Counts.text =counts1

 

If ( counts.text == (10).toString())

}

 

How would I modify this counter to count up when it hits a specific  Frame on a timeline ?  Would I add an ''if" Function to the string? 

 

Pleasw help