This content has been marked as final. Show 6 replies
Above I have posted some example code.
So far, all the books I have on Flash (Foundation ActionScript for Flash 8 and Learning ActionSCript 2.0 for Macromedia FLASH 8) put all their functions on the outermost scope, like in the first example, so basically they can be called from anywhere in the problem.
In an effort to better organize code, though, the second method looks better to me, because subFunction is only used in mainFunction. There will be no need to call subFunction outside of mainFunction's scope.
In my own programs, I've nested a function in another function's scope and sometimes it worked, sometimes it didn't. I never really explored why it worked sometimes and other times it didn't.
However, do people code the second way, or are functions in Flash usually left on the main scope? I guess I'm basically trying to do it the second way to help encapsulate and organize my functions in an ActionScript that is running at 300+ lines and probably will be close to 500 or 600 lines when it's all said and done.
Or is what I'm trying to accomplish more appropriate for an OOP approach to my program?
what's the question?
I was typing it up as you replied. Sorry about that.
Beat you by three seconds. :)
nesting functions makes your code harder to read and interpret. i can't argue about what looks better to you. if you're the only one looking at your code, do whatever you want. noone will care.
however, if you start using
to define your functions, you'll run into a problem (where the subfunctions are not defined until after the outer-nested function is called).
I'm trying to teach myself good coding habits (including typing and setting initial values for all my variables), so if you say that it's not done or good coding practice, I'll defer to your expertise and avoid coding in this way. :)
that's probably best, especially if you start coding your own class files. scope issues are tough enough without nesting function in class files. i believe you'd have more scoping issues if you nest functions.