using Object to store semi-categorised content in your programs

I had a project requiring me to store a class name, a colour, and a title for a particular ‘brush’ in this semi-painting program. Rather than run three separate arrays with the same index referring to the single item, I went with inserting objects into the array and then referencing the variables from that object index. Clear as mud – here’s an example:

Create an object, brushObject, then input these various variables into it.

// dirt
var brushObject:Object = {
  name: "dirt",
  displayname: "Dirt",
  palette: Class(dirt_texture)
};
brush.push(brushObject);

Then we push that into the brush Array. Therefore, to say, reference the palette class at later stages, I can reference the object (or others I put into the brush Array) in a more descriptive manner, ie.

brush[0].palette // outputs dirt_texture
Tech Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑