Search code examples
actionscript-3starling-framework

Actionscript 3 Injecting string to an existing variable/constant


very simple question that I cannot find an answer to:

private const LEFT_HOUSE_2_X:Number = 445;
private const LEFT_HOUSE_2_Y:Number = 145;
private const LEFT_HOUSE_2_WIDTH:Number = 45;
private const LEFT_HOUSE_2_HEIGHT:Number = 35;

How can I use access the constant above if I am using an iterator: e.g.

var i:uint = 2;

LEFT_HOUSE_{ i }_X ?

Also to be done with a variable.


Solution

  • using square brackets you can read a const or variable with variable name

    this["LEFT_HOUSE_"+i+"_X"]