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];
}
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:
...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);
use
parent.gotoAndStop(2)
no, you would use
if(this.currentLabel== yourlabel){
count=0;
}
yourbutton.addEventListener("MouseEvent.CLICK,f);
function f(e:MouseEvent):void{
counter=0;
}
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
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)
Copy link to clipboard
Copied
In the Output :
It shows
0
Tf 1
1
2
3
(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
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.
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?
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);
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
Copy link to clipboard
Copied
is that code on more than one frame?
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
Copy link to clipboard
Copied
you're welcome.
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
Copy link to clipboard
Copied
replace the 2nd trace with:
if(counter==5){
gotoAndPlay(whatever)
}
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
Copy link to clipboard
Copied
the easiest way would be to add your gotoAndStop/gotoAndPlay to the movieclip's last frame
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
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)
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)
Copy link to clipboard
Copied
if(your condition){
counter=0;
}
Copy link to clipboard
Copied
If I put the frame label where you put 'your condition' - will that reset the count?
Copy link to clipboard
Copied
no, you would use
if(this.currentLabel== yourlabel){
count=0;
}
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?
Copy link to clipboard
Copied
I mean how do I create a button that can reset that same counter back to zero*
Copy link to clipboard
Copied
yourbutton.addEventListener("MouseEvent.CLICK,f);
function f(e:MouseEvent):void{
counter=0;
}
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
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.