[AS3] Disjointed code blues

I’ve made the switch from AS 2.0 to AS 3.0. I can pretty much get my game working, and it runs much faster than the same thing would under 2.0. You’d think I’d have nothing to complain about, right?

But I can’t help it. I really miss the simplicity of new.onEnterFrame = Function. Now it’s like my update function is inside a seperate AS file, with the class definition, and I have to call tempEnemy.update() once per frame. Only, nothing inside the class can see outside the class, so I can’t just do like this.angle=lookAtPlayer(this) anymore. In order for objects to interact with each other in any menaingful way, I need the eyes, ears, and a large portion of the brains of the objects to exist in the main program loop, outside the AS file.

I thought OOP was supposed to make code more compartmentalized? this.onEnterFrame() = function(){tryToKillThePlayer(this);} was compartmentalized. All I had to do was make my Thing, spawn it, and it would work. All the code for my Thing was in Thing.onEnterFrame, which was defined anew every time I attached a Thing to the screen. AI, collision detection, all in one place. Compartmentalized.

Now my Thing’s brains are strewn all over the main timeline (or in a game.as file if I were massochistic enough to eschew the timeline approach,) with some scraps of basic functionality tucked into the class. And this is supposed to be MORE compartmentalized?

And that’s to say nothing of variable names. My god. Instead of just going thing.health=100 in the main timeline (which i understand now results in a MEMORY LEAK unless you follow some byzantine delete protocol… it didn’t cause a memory leak before; why would it now? OMG THEY ADDED A BUG) first I have to add a health variable to my class. Then I have to make it private, and add getters and setters. BUT WAIT! The getters and setters need to have UNIQUE NAMES, so I have to call the internal variable thingHealth or something, if I want the public interface to use the keyword “health.”

In other words, the programmer who writes the class file and the programmer who writes the main game code MUST use different variable names, even though they mean the same thing. That means if I’m the ONLY person working on my game, I need to remember to use health in my main timeline and Thing1Health in the Thing1 class, Thing2Health in the Thing2 class, etc. Seperate keywords means seperate implementations… I can’t even copypaste code from existing objects to create new objects! What the hell ever happened to code reuse? I’m not just reinventing the wheel, here, I’m making up new words for ROUND so that I CAN re-invent the wheel.

I can only assume that I’m doing it wrong. I thought OOP was supposed to be all about compartmentalized code and code reuse, but so far the transition from 2.0 to 3.0 is only making my code messier, harder to understand, it takes three times as many lines to implement the same ideas, and I don’t think I’ll be able to reuse these classes in future games without basically rewriting parts of them.

It is blisteringly fast in terms of code execution, though, so I’ll of course keep using it. I just don’t get this whole “outside looking in” paradigm. I know how to comply with it, I just don’t like or appreciate it.

Someone please tell me what the deal is. Or if I’m using it wrong, then explain how I can neatly and concisely pack my monster’s graphics, code, and interactive behavior into a single class file.