Friday, January 12, 2007

Flash PnC tutorial – 4. Instantiation

Generally, the point behind objects is to create items that have specific behaviors that can be re-used over and over. For example, inventory objects share common behaviors, such as dragging and dropping them on things. What I haven’t figured out yet in my very brief acquaintance with Flash is how to create a library of behaviors not tied to a specific picture. A typical PnC inventory will be between 6 and 20 diverse objects, i.e. knife, hammer, screwdriver, teddy bear, unopened magical box, lighter, any number of keys, papers with codes, mysterious object of unknown purpose, etc. In other words, although they share the drag/drop behavior and will probably grey-out when they’ve been used, they all have different graphic images. And the object library seems to start with the graphic, rather than the behavior.

I’ll address that when I figure it out. Anyway….

The only place where I’ve found the library particularly useful is in making buttons. The general way of making a button is to draw a borderless box (or circle) of appropriate proportions, select it and press F8. Name it as desired, convert it to a button with the registration mark in the center, then go to Properties and set the alpha to zero. Instant button.

This results in two things in your library. A graphic of the box you just drew, and a button object. They are irrevocably tied to each other. If you delete the picture, the box will disappear from your button object. Bizarre but true.

If you go about happily drawing separate boxes and converting them for every single button in your game, your object library will quickly become overwhelmed with a huge number of boxes, both graphic and object.

Don’t do this. Create one button object for your library, and whenever you need a button, drag and drop it from the library and resize it. Leaving you with a grand total of one object and one graphic in your library. Much more tidy and obviously a much smaller library size. These dropped versions are instances, and each instance can have its own name, its own code and size/shape.

No comments: