“If you’re not burning with rage, you’re not learning computer skills”

Code Duplication

I’m running into duplication problems that seem to be inherent to Flash itself. Here’s the deal:

We have 5 player characters which have been designed in Flash Professional. As of now they are just colored blocks (“why do they gotta be colored? That’s racist”). These characters obviously share certain properties, like for example HP, MP, that sort of thing; that’s not a problem for the most part: I can simply have each PC class extend a base class that has those properties and they’ll inherit them just fine.

That’s great for properties that you can define in code, but what about shared properties you want to design within Flash Professional itself? For example, as a temporary element each PC has a text box which they can manipulate to say certain things: e.g. “Ouch,” when nailed by a ninja star. This is the kind of thing that we don’t want to duplicate so we would keep that text box in the parent class; but there’s no way that I know of right now to extend a parent class and work with it inside FP. You want to be able to extend Library objects, basically.

Thinking off the top of my head, maybe you could achieve something like this by combining different Library objects which each have their own code. If you properly nested things each “child” (really a compound of sorts) the code duplication would be small. However the whole concept is still rooted in duplication – you have five classes that must contain all the same elements; in fact the duplication just moves into FP, which is worse in a way.

Another way might be to have a single PlayerCharacter class which contains all the necessary design stuff, then skin each instance with a certain set of animations. This might make the most sense of all, if such a thing is possible or I knew what I was talking about here.

The solution that I’ve adopted now is to abstract out as much as possible and duplicate as little as possible. So in the case of the message boxes, the parent class has a method say(String) which gets called in all the appropriate cases; that method in turn calls another method say_internal(String) which is a stub in the parent class but which each child class can override. (Note that method names have been changed to protect the innocent – I’m not really sure what the proper naming here would be.) Thus to make the text appear in the box we’re only duplicating a few lines of code:

override function say_internal(str:String):void {
statusText.text = str;
}

That’s not great, but it does save us some implementation work. The real question I don’t really know yet is how big a problem this is: my example is contrived and temporary. What are the real, lasting situations in which this issue might arise?

Wat

It’s now become clear that I have reached the point in Flash Pro where I don’t know what the fuck is going on and I won’t be able to continue until I figure that out. I mean, to the basics, and no progress should be made until I get there.

I just spent an hour trying to figure out some bug I thought was of my own creation, only to realize that my entire fundamental understanding of what was going on is totally incorrect. Each Ninja gets placed in one of five lanes, one per player. In order that Ninjas in the same lane don’t overlap one another completely I introduced some randomization to their y position. Unfortunately some Ninjas were appearing outside of their given lanes; I spent some time debugging it, going over the randomization code and working through the math over and over.

It didn’t make any sense, until I checked things out in FP. Then it made even less sense. The sizes of all the characters are supposed to be 76px, but they’re all actually 80px tall scaled down by some percentage. Worse, each lane is supposed to be 86px high, but they’re being reported at runtime as anywhere from 170-190px. I can’t even find those numbers in FP to even start to make sense of them.

Trying to remove the transforms – scaling in this case – on the ninjas is totally ineffective. So… do you have to draw it the exact right size the first time, otherwise you’re screwed? I just want to change the size of a fucking square, you know? I don’t even know how to approach the lane height problem, since I can’t even see where the error is coming in.

Maybe I should be using scaleHeight or some other such thing at runtime? But really, this just points to my fundamental non-understanding of what’s happening in FP. So any further hacking around in FP or code is only going to fuck things up more. It’s time to sit down and do some hard core reading.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>