creating simple data-objects in runtime

hi folks!

how do you create a simple set of data, something like an Object with its own properties? do I need to create a class before or could i create it in runtime?

i want to create something like that:

private var myObject : Object = new Object();
myObject.theTextarray : Array = ["foo", "bar"];
myObject.theColor : String = "0x00FFFF";


Looks like you are trying to create just a generic object, and assign your own properties. What you have to do is create a class and define those specific properties that you want to set.

I'm much more familiar with C# than java, but hopefully this will help:

public class ColoredText
    private readonly string[] m_Text;
    private readonly Color m_Color;

    public ColoredText(string[] text, Color color)
        m_Text = text;
        m_Color = color;

    public string[] Text
        get { return m_Text; }

    public Color Color
        get { return m_Color; }


// Here is your code that creates the ColordText object
void CreateColoredTextObject()
    string[] textStrings = new string[] { "This", "Is", "Some", "Text" };
    ColoredText coloredText = new ColoredText(textStrings, Color.Red);

Hopefully that helps

Yes, you need to create a class which defines those specific variables. It's a good idea to create your class in its own separate script file, and name the file the same name as the class name. In Javascript this would be:

// --- ColorTextThing.js ---
class ColorTextThing {

    var textArray : String[];
    var color : Color;


Then, in your other scripts, you can use it like this:

private var myObject = new ColorTextThing();
myObject.textArray = ["foo", "bar"];
myObject.color = new Color(0,1,1,0); // this is like 00FFFF :-)