Skip to main content
July 30, 2013
Question

Turn input text string into numeric variable

  • July 30, 2013
  • 4 replies
  • 1101 views

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

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Ned Murphy
Legend
July 30, 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.

July 30, 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

Ned Murphy
Legend
July 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.