Every once in a while you inherit some project to fix up something that “some guy who did some Flash work for us a few years back” did. Sometimes you luck out and it’s not that bad. My coworker, Sam was not so lucky today. He got one of those ones with code on movie clips nested x levels deep. We call it “Jungle Code”, because it’s like hacking your way through vines and underbrush, watching out for snakes and alligators.
Beautiful, beautiful stuff like this gem:
_root.submenu.subbtn.vgnmenu.vgnbtn.tab1.onEnterFrame = root.submenu.subbtn.vgnmenu.vgnbtn.tab1.onoff;
This line was in a function along with about a dozen other almost identical statements. This function was called from a button. There are thirty other buttons which call thirty other similar functions.
Or this one:
this.onPress = function() { _root.actnumb = "00010101"; tellTarget (_root.navloader) { play(); } }
So we have a movie clip defining a callback for itself which uses tellTarget to tell a movie clip on _root to play! That is pure ART! actnumb, indeed!
[Edit: although this post is 3 1/2 years old, the owner of http://www.junglecode.net/ recently requested a link here. Not that the site has anything to do with this post, but, he’s an Adobe employee, so what the heck. :)]
I think I need a beer with lunch today :'( and a bigger machete!
Why don’t you people re-write it? All this talk of good commenting so future people can understand your code is rubbish; Flash isn’t MFC; and Flash 5 projects are always better off re-written anyway. Just see how it works, get the concept, and re-write the mug.
…of course, any excuse for a beer is a good excuse…
Yeah that’s the basic idea explore, cry, re-write.
Yes, I’m all for re-writing
_root.submenu.subbtn.vgnmenu.vgnbtn.tab1.onEnterFrame = root.submenu.subbtn.vgnmenu.vgnbtn.tab1.onoff;
once I figure out what the hell it means. 😉
We don’t have time rewrite that code…get back to work!
“I feel numb… too much is not enough.”
— “Numb” by U2
You’d probably enjoy http://thedailywtf.com and http://thephpwtf.com. Someone should set one up for Flash. 🙂
I once heard of a guy extending the timeline to allow time for a loadVariables action 🙂 That must have been fun… Best of luck to you Sam! 😀
i’ve been guilty of _contributing_ to “not-so-beautiful” code myself; when I inherit a project like you have here, and the client isn’t willing to pay up to redo the UGLY bits… well… let’s just say I make sure my code works, but do not really care if i’m adding to the ugliness ;P… take this one project i had for instance, among other things, the client’s code was using one function to update almost everything… not that this is a bad thing in itself… in this instance, however, they had bundled all the properties of the various forms (tons of them) into one function… so that at any one time you made that function call, you might _actually_ be updating like 5% of the members within… so I bring it up, and I get the “well… it works” response… they weren’t willing to pay up for a few more hours of work, and I had taken enough BS from them already and frankly wanted to get done and away with it… guess what I did… MADE THAT FUNCTION CALL ;P … there were other bits that just force you to write bad code TOO… of course, I could rewrite, like Jester proposes here… but on whose dime?
But its a lost art to write a stunning example of code like that lol
http://www.mindprod.com/unmain.html
What’s worse is when the so called “jungle code” was written by fairly respected members of the flash community, as in my case. I won’t name names. 🙂
I guess sometimes the budget just doesn’t allow for coding something properly. :-/
My favourite from the project I’m working on at the moment:
// update everything
updateEverything ();
// do it again, just in case
updateEverything ();
I leave the updateEverything function to your imaginations. It’s a doozy.
Hi, guys!
Was ‘glad’ to continue code like that. After months of contributing to this project, i came to rewriting it, which took much less than understanding it and then contributing. So, it’ll be less harmful to rewrite the project entirely. The main problem of the code like this is it’s absolutely close-to-impossible debugging, which take hours and hours.
So, once again. My opoinion is REWRITING the project entirely, from scratch.