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

Turn input text string into numeric variable

Guest
Jul 29, 2013 Jul 29, 2013

Hello again

I would like to set up a page with four input fields where a user can enter a number.

I then want to store those values as variables that I can use to perform calculations.

I'm struggling to get this to work - I suspect because my variables are set up as numbers, and my input fields accept strings.  How can I marry the two together? 

What I've got so far is:

inputReviewAll(null);

function inputReviewAll(event:Event):void
{
      var ReviewNumber:Number = Number(txtNoReview.text);
      var ApproveNumber:Number = Number(txtNoApprove.text);
      // and so on for other two variables
}


// txtNoReview.text = ReviewNumber.toString();

Thank you

M Hetherington

TOPICS
ActionScript
1.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
LEGEND ,
Jul 29, 2013 Jul 29, 2013

I don't see anything wrong with what you show.  I would normally define the function before I call it, but that appears to compile okay as is. 

What problem are you having?  I suspect the problem lies in something you aren't showing.

Make sure the textfield are designated as Single LIne, not Multiline.  That might be something that could cause a problem.

Since the variables are defined within that function their scope is limted to within that function... so if you are trying to use them elsewhere that won't work.

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
Guest
Jul 29, 2013 Jul 29, 2013

Yes, sorry, I probably didn't explain enough.

The problem I am having is that when I click the Next arrow to go to the next frame; and then the Previous arrow to come back to this frame; all my values wipe.

So if my default values are 0, 0, 0 and 0; and I change them to 1, 2, 3, 4; they reset to 0, 0, 0 and 0. 

So I need to work out how to make the variables 0, 0, 0 and 0 the first time someone opens the page.  But then once the input values are changed they stay changed.

Did that make any sense?

M Hetherington

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
LEGEND ,
Jul 30, 2013 Jul 30, 2013

What code do you use to set them to the default values (0)?

What you probably need to do is use a conditional that tests the values and if they are not assigned a value you assign the default, otherwise you leave them alone.

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
Guest
Aug 01, 2013 Aug 01, 2013
LATEST

The number was coming from text I had typed in the field.

I've been playing with this some more, and I'm still struggling.

Now I'm defining a numeric variable in Frame 1:

     var totalBudget:Number = 0;

Then on Frame 14 I am saying

     onBudgChange(null);

     txtBudget.addEventListener(Event.CHANGE, updateBudget);

     function updateBudget(event:Event):void {

          totalBudget = Number(txtBudget);

     }

     function onBudgChange(event:Event):void {

          txtBudget.text = totalBudget.toString();

     }

I can add text to the field OK, but if I go back and forward to the same frame I get "NaN" displayed.  So I'm guessing somehting is wrong with my "totalBudget = Number(txtBudget)" code - I just don't know what.

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