Copy link to clipboard
Copied
My input textfield is called Minutes.
var pMinutes = Minutes.text
var sMinutes:Number = Number(pMinutes)
I use it in a timer, and when i try to add a value to Minutes (ex. 5) in the swf the timer displays 59:59, if i add a value (ex. 5) in the .fla the timer goes well but i have to add a value before exporting... so the textinput is like a normal read-only text field.
Complete code:
import flash.events.*;
var ScoreHome:Number = 0;
HomeScore.text = scoreFormat(ScoreHome);
var ScoreGuest:Number = 0;
GuestScore.text = scoreFormat(ScoreHome);
var pMinutes:String = Minutes.text
var sMinutes:Number = Number(pMinutes)
var timePattern:RegExp = /\d\d\:\d\d(?=\s)/;
var secondPattern:RegExp = /(?<=\:)\d\d(?=\s)/;
var time:Date = new Date();
var SecondsM:Number = sMinutes * 60
var timer2:Timer = new Timer(1000, 24);
timer2.addEventListener(TimerEvent.TIMER, countdownpossesso);
//timer2.start();
var timer:Timer = new Timer(1000, SecondsM);
timer.addEventListener(TimerEvent.TIMER, countdown);
//timer.start();
HomeScore.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleradd);
ButtonminusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminus);
//StartSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerSS);
//StopSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerStS);
ResetSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerRS);
Reset24.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler24);
GuestScore.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleraddg);
ButtonminusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminusg);
Seconds.text = "06:00";
Possesso.text = "24";
function countdown(e:TimerEvent):void
{
time.time = (timer.repeatCount - timer.currentCount) * 1000;
Seconds.text = time.toString().match(timePattern)[0];
if (timer.repeatCount == timer.currentCount) {
playSound(Event);
}
}
function countdownpossesso(e:TimerEvent):void
{
time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
Possesso.text = time.toString().match(secondPattern)[0];
if (timer2.repeatCount == timer2.currentCount) {
playSound(Event);
}
}
function playSound(Event):void {
mySound.play()
timer.stop()
}
function scoreFormat(value:Number):String
{
return String(value <= 9 ? "0" + value : value);
}
function fl_MouseOverHandleradd(e:MouseEvent):void
{
ScoreHome++;
HomeScore.text = scoreFormat(ScoreHome)
;
}
function fl_MouseOverHandlerminus(e:MouseEvent):void
{
if (ScoreHome > 0) {ScoreHome--;}
HomeScore.text = scoreFormat(ScoreHome)
;
}
function fl_MouseOverHandlerSS(e:MouseEvent):void
{
timer.start()
timer2.start();
}
function fl_MouseOverHandlerStS(e:MouseEvent):void
{
timer.stop()
timer2.stop();
}
function fl_MouseOverHandlerRS(e:MouseEvent):void
{ timer.reset()
timer2.reset() ;
Seconds.text = "06:00";
Possesso.text = "24";
if(!fl_ToPlay_11)
{
fl_ToPlay_11 = !fl_ToPlay_11;
}
}
function fl_MouseOverHandleraddg(e:MouseEvent):void
{
ScoreGuest++;
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandlerminusg(e:MouseEvent):void
{
if (ScoreGuest > 0) {ScoreGuest--};
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandler24(e:MouseEvent):void
{
timer2.reset()
timer2.start()
timer.start()
Possesso.text = "24";
}
var mySound:Sound = new Buzzer();
startstop.addEventListener(MouseEvent.MOUSE_OVER, fl_ClickToPlayStopSound_11);
//This variable keeps track of whether you want to play or stop the sound
var fl_ToPlay_11:Boolean = true;
function fl_ClickToPlayStopSound_11(evt:MouseEvent):void
{
if(fl_ToPlay_11)
{
timer.start()
timer2.start();
}
else
{
timer.stop()
timer2.stop();
}
fl_ToPlay_11 = !fl_ToPlay_11;
}
"timer" is the interested timer.
Copy link to clipboard
Copied
i can't determine if you have a question but, if you're seeing string addition when you want arithmetic addition, make sure the two numbers you're adding are both numbers.
Copy link to clipboard
Copied
The addition is perfect only if i add in the input text tfl the number before pressing ctrl+enter... this is 'cause i added a number that connect to the string... and goes pretty well.
My question is:Do i need a function to change the textinput value in non-editing mode?
Example
Timer 6.00
i modify the textinput with 7
the function reads the number
Modify the timer in 7:00
Copy link to clipboard
Copied
all textfield text is a string. if you don't need any arthmetic operations on that string, you don't need to convert it to a number.
Copy link to clipboard
Copied
The timer reads Seconds like 60 * var so i need to convert it
Copy link to clipboard
Copied
ok. do you still have a question?
Copy link to clipboard
Copied
Ok, ill' be more explicit

This is the FLA. The selected TextField is an Input TextField with the instance name of "Minutes". In the FLA I assign it a random value (1)

This is the exported SWF. In minutes you can see "1", and the timer goes well (1 minute)

This is the exported SWF with Minutes modified in 4. The timer continues to display 1.
I hypotized that the timer read the value i assigned in the FLA.
SO my question is
HOW CAN THE TIMER READ THE VALUE MODIFIED IN THE EXPORTED SWF ???
Copy link to clipboard
Copied
is Seconds the name of the textfield where you countdown time? if yes, i don't see where that value has anything to do with your Minutes textfield so why would you think changing Minutes' value would change the display in Seconds?
Copy link to clipboard
Copied
var pMinutes = Minutes.text
var sMinutes:Number = Number(pMinutes)
...
var SecondsM:Number = sMinutes * 60
var timer:Timer = new Timer(1000, SecondsM);
Copy link to clipboard
Copied
test your code for 1 or 2 seconds after adding the trace() functions shown below to those functions shown below. copy and paste the trace() output from:
function countdown(e:TimerEvent):void
{
time.time = (timer.repeatCount - timer.currentCount) * 1000;
Seconds.text = time.toString().match(timePattern)[0];
trace(Seconds.text,timer.repeatCount-timer.currentCount);
if (timer.repeatCount == timer.currentCount) {
playSound(Event);
}
}
function countdownpossesso(e:TimerEvent):void
{
trace("**");
time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
Possesso.text = time.toString().match(secondPattern)[0];
if (timer2.repeatCount == timer2.currentCount) {
playSound(Event);
}
}
Copy link to clipboard
Copied
I have done like you said, but nothing changed.
If i confused something, i post my code.
import flash.events.*;
var ScoreHome:Number = 0;
HomeScore.text = scoreFormat(ScoreHome);
var ScoreGuest:Number = 0;
GuestScore.text = scoreFormat(ScoreHome);
var pMinutes:String = Minutes.text
var sMinutes:Number = Number(pMinutes)
var timePattern:RegExp = /\d\d\:\d\d(?=\s)/;
var secondPattern:RegExp = /(?<=\:)\d\d(?=\s)/;
var time:Date = new Date();
var SecondsM:Number = sMinutes * 60
var timer2:Timer = new Timer(1000, 24);
timer2.addEventListener(TimerEvent.TIMER, countdownpossesso);
//timer2.start();
var timer:Timer = new Timer(1000, SecondsM);
timer.addEventListener(TimerEvent.TIMER, countdown);
//timer.start();
HomeScore.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleradd);
ButtonminusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminus);
//StartSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerSS);
//StopSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerStS);
ResetSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerRS);
Reset24.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler24);
GuestScore.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleraddg);
ButtonminusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminusg);
Seconds.text = "06:00";
Possesso.text = "24";
function countdown(e:TimerEvent):void
{
time.time = (timer.repeatCount - timer.currentCount) * 1000;
Seconds.text = time.toString().match(timePattern)[0];
trace(Seconds.text,timer.repeatCount-timer.currentCount);
if (timer.repeatCount == timer.currentCount) {
playSound(Event);
}
}
function countdownpossesso(e:TimerEvent):void
{
trace("**");
time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
Possesso.text = time.toString().match(secondPattern)[0];
if (timer2.repeatCount == timer2.currentCount) {
playSound(Event);
}
}
function playSound(Event):void {
mySound.play()
timer.stop()
}
function scoreFormat(value:Number):String
{
return String(value <= 9 ? "0" + value : value);
}
function fl_MouseOverHandleradd(e:MouseEvent):void
{
ScoreHome++;
HomeScore.text = scoreFormat(ScoreHome)
;
}
function fl_MouseOverHandlerminus(e:MouseEvent):void
{
if (ScoreHome > 0) {ScoreHome--;}
HomeScore.text = scoreFormat(ScoreHome)
;
}
function fl_MouseOverHandlerSS(e:MouseEvent):void
{
timer.start()
timer2.start();
}
function fl_MouseOverHandlerStS(e:MouseEvent):void
{
timer.stop()
timer2.stop();
}
function fl_MouseOverHandlerRS(e:MouseEvent):void
{ timer.reset()
timer2.reset() ;
Seconds.text = "06:00";
Possesso.text = "24";
if(!fl_ToPlay_11)
{
fl_ToPlay_11 = !fl_ToPlay_11;
}
}
function fl_MouseOverHandleraddg(e:MouseEvent):void
{
ScoreGuest++;
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandlerminusg(e:MouseEvent):void
{
if (ScoreGuest > 0) {ScoreGuest--};
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandler24(e:MouseEvent):void
{
timer2.reset()
timer2.start()
timer.start()
Possesso.text = "24";
}
var mySound:Sound = new Buzzer();
startstop.addEventListener(MouseEvent.MOUSE_OVER, fl_ClickToPlayStopSound_11);
//This variable keeps track of whether you want to play or stop the sound
var fl_ToPlay_11:Boolean = true;
function fl_ClickToPlayStopSound_11(evt:MouseEvent):void
{
if(fl_ToPlay_11)
{
timer.start()
timer2.start();
}
else
{
timer.stop()
timer2.stop();
}
fl_ToPlay_11 = !fl_ToPlay_11;
}
Copy link to clipboard
Copied
do you see trace output when you test?
Copy link to clipboard
Copied
*yes
[SWF] CountDownApp.swf - 1209754 byte dopo la decompressione
00:59 59
**
00:58 58
**
00:57 57
**
00:56 56
**
always, also if i put 5 in the TextInput
Copy link to clipboard
Copied
now, use:
import flash.events.*;
var ScoreHome:Number = 0;
HomeScore.text = scoreFormat(ScoreHome);
var ScoreGuest:Number = 0;
GuestScore.text = scoreFormat(ScoreHome);
var pMinutes:String = Minutes.text
var sMinutes:Number = Number(pMinutes)
var timePattern:RegExp = /\d\d\:\d\d(?=\s)/;
var secondPattern:RegExp = /(?<=\:)\d\d(?=\s)/;
var time:Date = new Date();
var SecondsM:Number = sMinutes * 60
var timer2:Timer = new Timer(1000, 24);
timer2.addEventListener(TimerEvent.TIMER, countdownpossesso);
//timer2.start();
var timer:Timer = new Timer(1000, SecondsM);trace("**",SecondsM);
timer.addEventListener(TimerEvent.TIMER, countdown);
//timer.start();
HomeScore.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleradd);
ButtonminusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminus);
//StartSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerSS);
//StopSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerStS);
ResetSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerRS);
Reset24.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler24);
GuestScore.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleraddg);
ButtonminusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminusg);
Seconds.text = "06:00";
Possesso.text = "24";
function countdown(e:TimerEvent):void
{
time.time = (timer.repeatCount - timer.currentCount) * 1000;
Seconds.text = time.toString().match(timePattern)[0];trace(Seconds.text,timer.repeatCount,timer.currentCount);
if (timer.repeatCount == timer.currentCount) {
playSound(Event);
}
}
function countdownpossesso(e:TimerEvent):void
{
time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
Possesso.text = time.toString().match(secondPattern)[0];
if (timer2.repeatCount == timer2.currentCount) {
playSound(Event);
}
}
function playSound(Event):void {
mySound.play()
timer.stop()
}
function scoreFormat(value:Number):String
{
return String(value <= 9 ? "0" + value : value);
}
function fl_MouseOverHandleradd(e:MouseEvent):void
{
ScoreHome++;
HomeScore.text = scoreFormat(ScoreHome)
;
}
function fl_MouseOverHandlerminus(e:MouseEvent):void
{
if (ScoreHome > 0) {ScoreHome--;}
HomeScore.text = scoreFormat(ScoreHome)
;
}
function fl_MouseOverHandlerSS(e:MouseEvent):void
{
timer.start()
timer2.start();
}
function fl_MouseOverHandlerStS(e:MouseEvent):void
{
timer.stop()
timer2.stop();
}
function fl_MouseOverHandlerRS(e:MouseEvent):void
{ timer.reset()
timer2.reset() ;
Seconds.text = "06:00";
Possesso.text = "24";
if(!fl_ToPlay_11)
{
fl_ToPlay_11 = !fl_ToPlay_11;
}
}
function fl_MouseOverHandleraddg(e:MouseEvent):void
{
ScoreGuest++;
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandlerminusg(e:MouseEvent):void
{
if (ScoreGuest > 0) {ScoreGuest--};
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandler24(e:MouseEvent):void
{
timer2.reset()
timer2.start()
timer.start()
Possesso.text = "24";
}
var mySound:Sound = new Buzzer();
startstop.addEventListener(MouseEvent.MOUSE_OVER, fl_ClickToPlayStopSound_11);
//This variable keeps track of whether you want to play or stop the sound
var fl_ToPlay_11:Boolean = true;
function fl_ClickToPlayStopSound_11(evt:MouseEvent):void
{
if(fl_ToPlay_11)
{
timer.start()
timer2.start();
}
else
{
timer.stop()
timer2.stop();
}
fl_ToPlay_11 = !fl_ToPlay_11;
}"timer" is the interested timer.
Copy link to clipboard
Copied
[SWF] CountDownApp.swf - 1209756 byte dopo la decompressione
** 60
00:59 60 1
00:58 60 2
00:57 60 3
00:56 60 4
00:55 60 5
00:54 60 6
00:53 60 7
00:52 60 8
00:51 60 9
00:50 60 10
Copy link to clipboard
Copied
and what was the number in your Minutes textfield?
Copy link to clipboard
Copied
i tried with 1, 3 and 5
Copy link to clipboard
Copied
and the trace() output is the same for all those????
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more