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

string needs to be changed to Number only

Community Beginner ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

Hello,

I am trying to make a converter. I have two boxes. One is input and the other one is dynamic. I have a button between the two that will do a conversion from centimeters (the Input box) to inches (dynamic box). The button's instance name is 'change', the Input box's instance name is 'centim' and the dynamic one's is 'inches'.

However, currently the Input one only accepts String characters of "letters". And it only accepts the letters of the instance name 'centim'. I want it to accept only numbers so that the the button in betwen will dipslay the converted number in the Dynamic one's box.

Here is my current code:

change.addEventListener(MouseEvent.CLICK, converting);

function converting(e:MouseEvent) {

    var convert:Number = (Number (centim.text * 2.56));

    convert = Math.round(convert)

    inches.text = String(convert);

}

I need one more line after the 'function', I assume to tell it to accept numbers than the instance name letters. But I do not know how to do it!!!

Could anyone offer any suggestions as to how to?

Thank you all for your time and consideration.

Best Regards,

Cagri Kasap

TOPICS
ActionScript

Views

818

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , May 30, 2013 May 30, 2013

1. embed your fonts

2. don't type any text into the input text field

3. use the restrict property to restrict the input textfield text to numbers.

4. use:

change.addEventListener(MouseEvent.CLICK, converting);

function converting(e:MouseEvent) {

    var convert:Number = Number (centim.text) * 2.56;

    convert = Math.round(convert)

    inches.text = String(convert);

}

centim.restrict="0-9";

Votes

Translate

Translate
Community Expert ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

1. embed your fonts

2. don't type any text into the input text field

3. use the restrict property to restrict the input textfield text to numbers.

4. use:

change.addEventListener(MouseEvent.CLICK, converting);

function converting(e:MouseEvent) {

    var convert:Number = Number (centim.text) * 2.56;

    convert = Math.round(convert)

    inches.text = String(convert);

}

centim.restrict="0-9";

Votes

Translate

Translate

Report

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 Beginner ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

Hello,

I embeded the fonts so right now I can write the numbers. I guess I even do not need the restriction anymore but now I cannot get the code operating. I can write the number in the Input text box and then press on the button but I cannot get anything oin the dynamic text box.

And I do not get any errors neither on the grammar page nor on the output compiler page. I do not understand what is going on? Can anybody help?

Thank you for your tome and consideration.

Best,

Cagri Kasap

Votes

Translate

Translate

Report

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 ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

make sure both textfields have their fonts embedded and no text entered into either in the ide.

what's the following show in your output panel after clicking change:

change.addEventListener(MouseEvent.CLICK, converting);

function converting(e:MouseEvent) {

    var convert:Number = Number (centim.text) * 2.56;

    convert = Math.round(convert)

    inches.text = String(convert);

trace(inches.text);

}

Votes

Translate

Translate

Report

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 Beginner ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

Hello,

Thank you very much for your advice. It really helped a lot. Tracing the

text was very intelligent. I can see the result in the output panel. That

means the function and code was working out fine. I actually just solved

the problem.

I have forgotten to change the background color and the text color to be

different. So it was working but showing the text in the same color with

the background so I was seeing the result but not noticing it.

Thank you very much for your help.

YOU ARE THE GREATEST!!!

Votes

Translate

Translate

Report

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 ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

LATEST

you're welcome.

(and, i've made that same text color=background color genius-move myself, more than once.)

Votes

Translate

Translate

Report

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