Highlighted

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

New Here ,
Jul 04, 2019

Copy link to clipboard

Copied

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];

}

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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];

}

TOPICS
ActionScript

Views

198

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Jul 04, 2019

Copy link to clipboard

Copied

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];

}

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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];

}

TOPICS
ActionScript

Views

199

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 04, 2019 0
Adobe Community Professional ,
Jul 05, 2019

Copy link to clipboard

Copied

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];

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 05, 2019 0
New Here ,
Jul 05, 2019

Copy link to clipboard

Copied

Thanks bro!! !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 05, 2019 0
Adobe Community Professional ,
Jul 05, 2019

Copy link to clipboard

Copied

you're welcome.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 05, 2019 0
New Here ,
Jul 07, 2019

Copy link to clipboard

Copied

Hi Its coming up with error

1119 - nend undefined property of current count

And when I add "target.Current count "

The count goes wierd and doesn't do the countdown.

Don't suppose you could try load it yourself onto a fla and send me a recorrected code without the error ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 07, 2019 0
Adobe Community Professional ,
Jul 07, 2019

Copy link to clipboard

Copied

that should be e.target.currentCount and e.target.repeatCount.  use:

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;

nend = _nend;

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.target.currentCount);

if (e.target.currentCount == e.target.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];

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 07, 2019 0
New Here ,
Aug 12, 2019

Copy link to clipboard

Copied

thank you

Do you know how I can switch the variables for it to count up instead of countdown now

Thanks so much !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 12, 2019 0
Adobe Community Professional ,
Aug 12, 2019

Copy link to clipboard

Copied

use:

var t: Timer;

var tf: TextField;

var nend: int;

countUp1F(00, 50, 50000, tf1);

function countUp1F(_nstart: int, _nend: int, duration: int, _tf: TextField): void {

if (_nstart < _nend) {

tf = _tf;

nend = _nend;

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

t.addEventListener(TimerEvent.TIMER, timer1F);

t.start();

}

}

function timer1F(e: TimerEvent): void {

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

if (e.target.currentCount == e.target.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];

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 12, 2019 0
New Here ,
Feb 06, 2020

Copy link to clipboard

Copied

hey Kglad 

 

Thanks so much for all the support you gave me over the timer function 

 

If wanted a button to string its values from another button so it has the same functions

 

How would I do it ?

 

I've tried playing around but it just says a message about 'expected boolean where string " etc 

 

I just want a button inherit its functions and source it from another frame 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
New Here ,
Feb 06, 2020

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

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);

}

 

 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
New Here ,
Feb 06, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
kglad LATEST
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0