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
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];
}
Copy link to clipboard
Copied
Thanks bro!! !
Copy link to clipboard
Copied
you're welcome.
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 ?
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];
}
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 !
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];
}
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
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?
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);
}
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
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.
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
Copy link to clipboard
Copied
you have an as3 project, correct?
Copy link to clipboard
Copied
Yes its an As3 project
Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
var counter:int;
if(counter){
counter++;
} else {
counter = 1;
Count.text = counter;
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
Copy link to clipboard
Copied
use:
var counter:int;
if(counter){
counter++;
} else {
counter = 1;
Count.text = String(counter);
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
Copy link to clipboard
Copied
use the trace function to debug.
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?
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.