• 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

3.1K

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

Copy link to clipboard

Copied

Hi the trace output is picking up the count 

( its just not showing in the  counter.text) anyway of make (counter.text = trace)  then the counter just pick up trace

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

did it show

 

undefined

1

 

that is what it should show.  to use trace with your textfield:

 

trace(counter)

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

Count.text = String(counter); 

trace("tf",Count.text)

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

In the Output :

 

It shows 

0

Tf 1

1

2

(etc)

 

Ive made the counter on frame 1 

And on frame 2 it has a)( gotoandplay(1)) 

 

So it bounces back to frame 1 over and over. But the counter doesnt Register the returns back to frame 1. I even frame lablled frame 1 as "Tf" and it didnt work. I have attached pictures below for clarity

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

oops, i'm blaming you for this one, but i perpetuated the problem.  use:

 

var counter:int;

if(counter){

counter++;

} else {

counter = 1;

Count.text = String(counter);

}

 

// ie, notice that last curly bracket.  i had it in my code, but then you omitted it and i started copying your code.

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

Even with curly bracket it doesnt run.

 

Maybe something like :

 

Var  count:int =1

Var increase:int=1

If  I can somehow add a variable where by There is a frame that is played it adds 1 to the 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 Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

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

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

The trace output recognises the frame count as it starts to count 1-100 very quickly as the timeline runs through. ( like in the pictures i Sent)  but it doesnt show Any increase on the counter

 

Just to clarify when you say two frame visits you mean when the timeline visits that frame twice. If thats the case then it does what I've explained above

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

is that code on more than one 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

ive re entered this code. And it seems to run now. It's counting with - Tf 1 tf2 tf3 etc in the Output. And when I make button to go back to that frame the counter counts the returns. So it works. Thanks Kglad 

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

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 ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

One small question - if I wanted add a function for when the counter reaches (5) that it plays a frame. Where would I put it in this code...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

replace the 2nd trace with:

 

if(counter==5){
gotoAndPlay(whatever)

}

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 17, 2022 Dec 17, 2022

Copy link to clipboard

Copied

So as soon as the movie clip finishs. I just want it to jump to a particular frame. How would I code that 

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 17, 2022 Dec 17, 2022

Copy link to clipboard

Copied

the easiest way would be to add your gotoAndStop/gotoAndPlay to the movieclip's last 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 17, 2022 Dec 17, 2022

Copy link to clipboard

Copied

It doesnt work as It doesnt reference any labels on the actual timeline. I get an error which states its not found the frame labels in movie scene. How would I do It so that It actual chnages to another clip on the main timeline line once It ends

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 17, 2022 Dec 17, 2022

Copy link to clipboard

Copied

which timeline are you trying to control?  eg, if you're trying to control the parent timeline, use

 

this parent.gotoAndPlay

 

if it's the parent's parent, use

 

this parent.parent.gotoAndPlay

 

etc

 

and you can short circuit understanding the relationship of the two timelines by using a global variable, if you get stuck.  (although using console.log(this) in both timelines should clarify the relationship)

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 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

Hey Kglad this counter works great - how do I get it to reset count back to zero ( when it hits a certain 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 ,
Feb 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

if(your condition){
counter=0;

}

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 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

If I put the frame label where you put 'your condition' - will that reset the count? 

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 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

no, you would use

 

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

}

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 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

Thanks that works. How do I make a button clear that same counter? As a button action is that 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 Beginner ,
Feb 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

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

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 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

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

 

function f(e:MouseEvent):void{

counter=0;

}

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 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

Thanks Kglad. Im trying to make a button that when you hold it down it keeps executing a repeated gotoAndPlay function. ( and when you release it - the function stops) 

 

I've been playing with different eventlisteners and longpress scrpit But cant seem to find one

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 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

i'm not sure that makes sense, but start a loop (eg, enterframe) and to repeatedly execute something that does make sense.

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