views:

39

answers:

2

I'm making a game in flash, and I want to have a whole bunch of different rooms that I can make and delete with code. Ordinarily I'd just use something like:

var room:Sprite = new room1();
game.main.addChild(room);

...but I'd have to export every room for actionscript. Is there a way to get them made just being symbols? If nothing else, I could layer all the rooms on top of each other in one symbol and set all but one invisible, but I'd prefer doing it this way with getDefinitionByName().

A: 

I think that you do have to export each for AS, but I'm not sure... however, if you do go the route of putting them all in one symbol, it will be much easier to make it a MovieClip, and put each on a different frame; you can then switch between rooms by going to the appropriate frame.

Zev
Okay, I'm not sure if I'll do your idea, maybe, but I guess you answered my question, so I'll accept it.
Ullallulloo
A: 

What distinguishes one room from another? What is different about them? Ideally, you would group those "differences" into a hierarchy of classes. As a simple example, if some rooms were blue, some rooms were red you might create the following classes:

Room
ColoredRoom

Where Room is the parent of ColoredRoom. Then, you'd give colored room a property like:

var color:Color;

And set that property to create three different rooms:

var redRoom:ColoredRoom = new ColoredRoom();
var greenRoom:ColoredRoom = new ColoredRoom();
var blueRoom:ColoredRoom = new ColoredRoom();

redRoom.color = new Color(255,0,0);
greenRoom.color = new Color(0,255,0);
blueRoom.color = new Color(0,0,255);

Once you "group" your classes, you shouldn't have to export more than a couple "types" of rooms. Each will have it's own set of properties that make it different from the other (perhaps different source image files or movieclips).

The basic point is, approaching your problem in terms of Objects should make things easier. Figure out:

if you had to lump your rooms into 2 or 3 different categories, what would they be?

and go from there. I hope that helps in some way,

--gMale

gmale