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

Converting a Input Text to Number

New Here ,
Aug 08, 2011 Aug 08, 2011

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.

TOPICS
ActionScript
3.0K
Translate
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 08, 2011 Aug 08, 2011

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.

Translate
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
New Here ,
Aug 08, 2011 Aug 08, 2011

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

Translate
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 08, 2011 Aug 08, 2011

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.

Translate
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
New Here ,
Aug 08, 2011 Aug 08, 2011

The timer reads Seconds like 60 * var so i need to convert it

Translate
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 08, 2011 Aug 08, 2011

ok.  do you still have a question?

Translate
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
New Here ,
Aug 08, 2011 Aug 08, 2011

Ok, ill' be more explicit

http://i53.tinypic.com/ohlph4.jpg

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)

http://i52.tinypic.com/2qd6e6w.jpg

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

http://i56.tinypic.com/2dtdgyt.jpg

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 ???

Translate
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 08, 2011 Aug 08, 2011

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?

Translate
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
New Here ,
Aug 09, 2011 Aug 09, 2011

var pMinutes = Minutes.text

var sMinutes:Number = Number(pMinutes)

...

var SecondsM:Number = sMinutes * 60
var timer:Timer = new Timer(1000, SecondsM);

Translate
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 09, 2011 Aug 09, 2011

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);
     }
}

Translate
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
New Here ,
Aug 09, 2011 Aug 09, 2011

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;
}

Translate
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 09, 2011 Aug 09, 2011

do you see trace output when you test?

Translate
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
New Here ,
Aug 09, 2011 Aug 09, 2011

*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

Translate
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 09, 2011 Aug 09, 2011

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.

Translate
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
New Here ,
Aug 09, 2011 Aug 09, 2011

[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

Translate
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 09, 2011 Aug 09, 2011

and what was the number in your Minutes textfield?


Translate
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
New Here ,
Aug 09, 2011 Aug 09, 2011

i tried with 1, 3 and 5

Translate
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 09, 2011 Aug 09, 2011
LATEST

and the trace() output is the same for all those????

Translate
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