Why SOMETIMES … (String == Number) ….

March 10th, 2008 by Jaap Kooiker

So I encountered a really weird, but probably “explainable” problem in AS2 yesterday.
We all know that
trace("200.1" == 200.1) //true
and
trace("200.2" == 200.2) //true
trace(”200.3″ == 200.3) //true


trace(”200.81″ == 200.81) //true
trace(”200.81″ != 200.81) //false

This above works fine…but the following is what scares me the most….
trace("200.82" == 200.82) //false
Why the hell is the above false ???? And the really weird thing is
trace("200.82" != 200.82) //false
also false ???
So… it is NOT the same and it is NOT NOT the same?…wtf is it. AS doesn’t seem to know what it is.

Ok, bear with me a second. The following:

trace(”200.83″ == 200.83) //true
trace(”200.83″ != 200.83) //false

…that seems alright

At this point, I tried to make some sense of it and applied the following rules….
If a string has one decimal….it turns out to work fine…
If a string has two decimals….it only works fine if the last digit is uneven…

The next thing to check is a string with three decimals and…there seems to be a different stupid rule here…check…

trace("200.811" == 200.811) //true
trace(”200.811″ != 200.811) //false

trace(”200.812″ == 200.812) //true (should be false according to last “rules”)
trace(”200.812″ != 200.812) //false

Hmmm, it seems that we can erase the above rules from our head. It works fine at this point…what is that about?

One more sample…the second decimal after decimal point is an even digit.

trace("200.821" == 200.821) //false
trace(”200.821″ != 200.821) //false

trace(”200.822″ == 200.822) //false
trace(”200.822″ != 200.822) //false

Oh my god…..the second digit after decimal point is even and it is always false?? I can’t seem to make sense of it….sorry…
I can probably go on and on with more samples (four / five / etc. decimal digits) but the point is clear….it’s fucked.

If I trace typeof, it all seems to be a Number

trace(typeof(parseFloat(”200.81″))) //number
trace(typeof(parseFloat(”200.82″))) //number
trace(typeof(parseFloat(”200.821″))) //number

Converting the String to a Number or use parseFloat doesn’t work….so don’t bother trying.

Maybe it has something (the way it parses a string to a number or visa versa) to do with rounding Numbers…see what Arno has to say

Jaap

Posted in Actionscript 2.0, Bugs, Flash 8, Flash CS3, Flex | 6 Comments »

Application registration point get’s *@$#* when using a div over the application

February 20th, 2008 by Jaap Kooiker

This is like…. what?
I recently discovered that there’s a problem with the registration point when a html layer (eg div) is placed above the flash runtime. For some weird reason the Application registration point is set to zero according to the x and y of the overlay div (see sample). I for sure cannot change that registration point so why is it changing. The other thing is that all content stays in place at the right coordinates, but the mouse position shows us (see example below) that the registration point changes - it looks like that anyway.
From my opinion this is a bug of the player. The weird thing is that this only occurs in FireFox and not in IE.
It could be a serious problem when you wan’t to know last registered mouseX and mouseY before “leaving” the stage.

note:
I got a rather “innovative” (read: not nice) sollution to know the last real mouseX and mouseY postion.
Keep the last 2 known positions in an array and stop registering on Event.MouseLeave. Use the fore-last position in you’re application to determine the last valid position.

Check this Sample

Is there someone who can tell me why this “Phenomenon” occurs? I would like to know….why…

Edit Firefox 2.0.0.12 / Fp 9.0.115.0:

Jaap Kooiker

Posted in Actionscript 3.0, Bugs, Components, Did you know?, Flex | 4 Comments »