Did you know that if you are testing if a value does not equal an empty string in javascript:v!=''
might return somewhat unexpected results if v is false
var v=false;
alert(v!='')
will alert false and not true as you might expect.
At first glance I said, well o.k. this does make sense because v is a boolean so the empty string is being cast to a boolean for the comparison yielding false.
so I tried
var v=false;
alert(''!=v)
I expected that now the false value of v will be cast to the 'false' string which obviously is not an empty string and that the alert will now show true.
but that does not work either.
finally:
var v=false;
alert(''!=String(v))
does work as expected and results in true being returned.
I wander if this is also the case in ActionScript ...
Wednesday, July 28, 2010
empty strings are (not) different then false
Sunday, June 29, 2008
Two Tips For Debugging Flash Warnings
If you develop Flash widgets or application you might (and should) be familiar with the flash log.
One of the biggest issues with this log is that all the warnings and trace messages just pile up there regardless of what swf sent them.
Here are two simple tips to trace the "Warning: name is not a function" messages:
1. The reason you get those is because you are trying to call a function on some variable does not have such a function in its prototype chain.
2. To be able to identify what line in your code is causing those messages you can force the player to write out "Comments" into the log using the following syntax:
({}).THIS_IS_A_COMMENT_TO_THE_LOG()
This will trigget the same type of warning and so by placing several distinct such comments you can narrow the search and find the code line at fault.
Tuesday, December 04, 2007
The class 'com.your.class' cannot be imported because its leaf name is already being resolved to imported class 'com.your.class'.
While I was refactoring some ActionScript2 code, I ended up with the above error message.
I searched the web and what I came up with was mostly the information that such a message actually exists.
so after figuring out why I got that error I decided to write about it here for your benefit. (Leave me a comment if it helped you).
well it turns out that this was cause by the following proccess:
I have an adbode flash source .FLA file which had inside its _root code two #include statements:
lets say
#include "fileA.as"
and
#include "fileB.as"
now each of those file in its turn had an import statement
import MyClass
where MyClass.as was a file that was on the same directory as the .FLA, fileA.as & fileB.as.
It worked fine.
But when I started refactoring and moved MyClass to become com.whatever.MyClass
(with all the required changes to MyClass, fileA and fileB) I suddenly got
"The class 'com.whatever.MyClass' cannot be imported because its leaf name is already being resolved to imported class 'com.whatever.MyClass'".
The solution was to remove the import statements from fileA.as and FileB.as
and just place one import directly in the .FLA.
(the #include files are on thair way out as well...)
My recomendation: Try to avoid #include, most likely you can get better results by using a static class.