• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Jul 04, 2019 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];

}

TOPICS
ActionScript

Views

2.2K

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
community guidelines

correct answers 5 Correct answers

Community Expert , Jul 05, 2019 Jul 05, 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:

...

Votes

Translate

Translate
Community Expert , Dec 12, 2022 Dec 12, 2022

what's the trace output after 2 frame visits

 

trace(counter);

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

}

 

Count.text = String(counter);

trace("tf",Count.text);

 

 

 

 

Votes

Translate

Translate
Community Expert , Dec 17, 2022 Dec 17, 2022

use

 

parent.gotoAndStop(2)

Votes

Translate

Translate
Community Expert , Feb 11, 2023 Feb 11, 2023

no, you would use

 

if(this.currentLabel== yourlabel){
count=0;

}

Votes

Translate

Translate
Community Expert , Feb 12, 2023 Feb 12, 2023

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

 

function f(e:MouseEvent):void{

counter=0;

}

Votes

Translate

Translate
Community Expert ,
Jul 05, 2019 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];

}

Votes

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
community guidelines
Community Beginner ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Thanks bro!! !

Votes

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
community guidelines
Community Expert ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

you're welcome.

Votes

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
community guidelines
Community Beginner ,
Jul 07, 2019 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 ?

Votes

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
community guidelines
Community Expert ,
Jul 07, 2019 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];

}

Votes

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
community guidelines
Community Beginner ,
Aug 12, 2019 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 !

Votes

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
community guidelines
Community Expert ,
Aug 12, 2019 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];

}

Votes

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
community guidelines
Community Beginner ,
Feb 06, 2020 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 

 

 

Votes

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
community guidelines
Community Beginner ,
Feb 06, 2020 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?

Votes

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
community guidelines
Community Expert ,
Feb 06, 2020 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);

}

 

 

 

 

Votes

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
community guidelines
Community Beginner ,
Feb 06, 2020 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

Votes

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
community guidelines
Community Expert ,
Feb 06, 2020 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.

Votes

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
community guidelines
Community Beginner ,
Dec 07, 2022 Dec 07, 2022

Copy link to clipboard

Copied

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 

 

Votes

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
community guidelines
Community Expert ,
Dec 07, 2022 Dec 07, 2022

Copy link to clipboard

Copied

you have an as3 project, correct?

Votes

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
community guidelines
Community Beginner ,
Dec 07, 2022 Dec 07, 2022

Copy link to clipboard

Copied

Yes its an As3 project

Votes

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
community guidelines
Community Expert ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

@kazemb 

 

attached to the frame where you want to add a counter, use:

 

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

}

// now do whatever with counter.  it's value indicates the number of times the playhead has entered this frame.

Votes

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
community guidelines
Community Beginner ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

I tried Using it - but how do I make this counter show up in the count.text =counter - ive put the code in and made a count.text but the counter isn't showing Any numbers heres my code below:

 

Count.text = counter

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

 

I was expectin that when the time line hits the frame it would show the actual count in the count.text but it doesnt show anything 

Votes

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
community guidelines
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

 

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

Count.text = counter; 

Votes

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
community guidelines
Community Beginner ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

"Implcit coercion of a value of type int to an unrelated type string "  got this error message - is this because the code doesnt recongnised the counter.text?  How would I fix this single error

 

Thanks again 

Votes

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
community guidelines
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

use:

 

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

Count.text = String(counter); 

Votes

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
community guidelines
Community Beginner ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Hey Kglad it works - but it doesnt count more then 1. If I make a button that goes to another frame. Then  go back on to the frame the count doesnt go up 

Votes

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
community guidelines
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

use the trace function to debug.

Votes

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
community guidelines
Community Beginner ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

Thanks Kglad - also how do put a code when a movie clip ends theres an action where it takes you to a particular frame? 

 

Votes

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
community guidelines
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

one problem at a time to prevent confusion 

 

to debug the code i suggested, use

 

 

trace(counter)

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

Count.text = String(counter); 

 

and enter this frame twice.  report the trace output.

Votes

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
community guidelines