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
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";
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";
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
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);
}
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!!!
Copy link to clipboard
Copied
you're welcome.
(and, i've made that same text color=background color genius-move myself, more than once.)