Stupid coding mistakes
Sometimes when coding I just get, well there’s no other word for it than, stupid. It usually happens in the late afternoon when the caffeine has worn off. ( That’s why I made this T-shirt. )
Here’s an account of some of the dumbest mistakes I’ve made.
Who left the window open?
If you’ve worked with AIR apps and opening multiple windows from the NativeApplication then you’ll know that one of the problems is getting the spawned windows to close. Not just a little closed but totally closed, out of memory, no references and garbage collected. Because if you don’t you won’t be able to launch your app again until you reboot.
So I was having this problem and ran across Christian Cantrell’s post about exactly how to handle it. Great. I copied his code snippit and pasted into my main app.
Tested it.
Nothing. The app wouldn’t launch.
Rebooted
Tested. Nothing.
Looking at the code. Looks good. Reboot.
Test. Nothing.
What the frak?
Oh, wait a second, I put the code in the init() method that’s called on creationComplete(). So the app was launching and then closing down right away. Yep, I did that.
GotoAndStop
Even when I was a Flash developer I was never much for the timeline. So after doing nothing but Flex apps for a few months I had to go back to Flash and work on an old app. The gist of the code was to control some MovieClips on a timeline. One of the buttons would make the animation start all over but for some reason it wouldn’t work.
Now when you’re used to working with fairly complex code on a daily basis and then gotoAndStop is kicking your ass you start getting frustrated quickly. At least I do.
Turns out the problem was that I was trying to gotoAndStop( 0 ). I was thinking in terms of an array index so it made since. But the Flash timeline isn’t 0 based. So gotoAndStop( 1 ) is the first frame.
The TextArea is not the text
The id of a text component is not the string of text that is displayed. No, that’s id.text. I’ve done that more times than I can count but usually I get an error. Something like, “blah, blah, blah, corruption of type string.” It just takes a second to realize the error and move on.
But once I was passing text values to a database via AMFPHP and it just kept failing. In this instance I didn’t get any errors. And I’m sure the PHP class that was getting the data was coughing up a hairball each time I tried sending it some component reference but it couldn’t tell me so.
Of course I eventually discovered the error of my ways and swore to never make that mistake again until I forgot about it, again and repeat the process all over. This is one of those common errors that just keeps coming back every few months to taunt me.
Where is that damn kid?
If you did Actionscript 2 development before going to Flex/Actionscript 3 then I’m sure you can feel my pain on this one: Creating a Sprite, drawing on it with the drawingAPI or rendering some BitmapData to it, and then . . . nothing. Check the code, no errors, no runtime errors. Check the code . . . yep, forgot to addChild, AGAIN! I still make this mistake all the time. But now it’s the first thing I look for.
creationComplete-Idiot
I wish I could edit the default page template in Flex Builder. You know, the default <mx:Application.. stuff. Mine would have an attribute for creationComplete=”init();”. And then I’d have the <script> block added with a private function init():void { …
Not only would that save me a few seconds of coding but it would save me from another common mistake: creating the init method but forgetting to call it on creationComplete. Don’t get me started. This one has cost me more time than forgetting to addChild.
GoldbergAIR application
With all these mistakes that I make so often I wish I could write an AIR app that could reach out and thump me on the forehead each time I repeat one. You know, if I created a plugin for Eclipse that detected these mistakes that notified an AIR app which then used Merapi to communicate with a Lego MindStorms contraption that extended it’s robotic arm… What a Goldbergian application that would be. :-)
What about you? Got some common errors that you make that you would like to share? Sometimes it helps to tell a stranger. Or at least to tell a strange blog. :-)
















