Skip to main content
Participant
March 28, 2007
Question

Is 0.48 restricted in Flash Action scripting when tracing?

  • March 28, 2007
  • 6 replies
  • 597 views
Hi...
I have a query....

I used a input text box with instance name "a". And i have to compare the value given by the user and proceed to next step.

But when i give "0.48" and compare it, i'm not able to proceed. my answer should be "0.48" only.
but when i declare a variable called "b" and give it the value "0.48" and comparing it, I get positive result.

I want to know why is it not taking from the input text box?

It would be great if any one could help me in this.

Thank you,
Sri...
This topic has been closed for replies.

6 replies

Inspiring
April 3, 2007
Roth is right here. Text isn't going to type cast to float or int during comparison. I've tried numerous times and always the same result of false. Before running your conditional tests, multiply the text field by 1.... something like this...

var a = myTextField.text;
a *= 1;

if(a == 0.48){
do something
}
Inspiring
April 3, 2007
If you tried what I said, it didn't show a=0.48.

It would have showed:

a is [0.48] and b is [0.48]

or something like that. You need those square brackets to make sure that there aren't extra characters or some such.

But the bottom line is that regardless of if you think somethings are equal, if Flash doesn't think they are equal there is a reason why.
Participating Frequently
April 3, 2007
try if (Number(a) == 0.48){
Inspiring
March 30, 2007
Did you try the trace statement?

If Flash says they aren't equal then they aren't equal.
Srini023Author
Participant
April 3, 2007
How can u say like that?

I traced it.. it shows a = 0.48

anybody plz help me to solve this......
Inspiring
March 29, 2007
You are missing the point. Text in a text box is text. Whether or not it LOOKS like a number. It is text. So in your first case.

a="0.48"

and "0.48" doesn't equal 0.48.

Additionally you will probably run into problems with the leading zero if you have numbers that start with that.

Remember, if a conditional statement is not being evaluated to true then no matter how crazy it seems the two things must not be equal. Try putting this line right before the if statement and see what it does.

trace("a is ["+a.text+"] and b is ["+b+"]");

What do you get?
Srini023Author
Participant
March 30, 2007
>You are missing the point. Text in a text box is text. Whether or not it LOOKS like a number. It is text.

For your kind information, I changed the answer to 0.49 and checked it, then it is working and when i change the answer back to 0.48 it doesn't work. So the point here is clear that its taking it as numbers not as a string. That's why I am asking this question here in this "Forum".

Inspiring
March 28, 2007
Hard to know from your description, but the usual guess should suffice.

Get this, the input from a text input box is of datatype String (or text).

You are probably comparing "0.48" to 0.48 which is of datatype Number.

By making b="0.48" you are saying it is a String and not a number and that would be why it works.

You can cast the or parse the text input field to a Number like this:

someVariable=Number(myTextField.text)
someVariable=parseFloat(myTextField.text)
Srini023Author
Participant
March 29, 2007
thanks for trying to answer me...

the data type is not a string it is numeric... i.e., b = 0.48
and in the input box we have to enter the number only... and the answer for the quetion i have is 0.48. So if i compare the answer from the input box, which is named as "a", i should be able to move forward.

if (a == 0.48){
// some functions to be followed
}
else {
stop();
}

here if i give 0.48 in the input box i'm not able to proceed, its just stopping as in else i gave to stop.

But if i declare a variable and assign it a value like below:
b = 0.48;

if (b == 0.48){
// some functions to be followed
}
else {
stop();
}
the o/p is that i'm able to do the functions which i want...

so plz help me now.

Thanks in advance.
Sri...