This feels like a newbie question, so brace yourself.
I am having difficulty getting a reference to elements added after compile-time using the 'id' property. I have seen a few forum topics suggesting that this isn't possible, and that getting a reference to elements added this way is trickier, but never just exactly what that trick is. This code throws a fun little: Error: uncaught exception: Error calling method on NPObject! [plugin exception: "ReferenceError: Error #1069: Property canvas_tentpoles_0 not found on SGraph and there is no default value."]
.
public function calledAfterInit(graph_values:Array):void
{
for(var i:int=0; i<graph_values.length; i++) {
var cdc:CartesianDataCanvas = new CartesianDataCanvas();
cdc.id = "canvas_tentpoles_"+i;
cdc.includeInRanges = false;
cdc.visible = false;
Areachart.annotationElements = Areachart.annotationElements.concat(cdc);
// [...do stuff...]
}
// [...later...]
for(var j:int=0; j<graph_values.length; j++) {
drawOnCanvas(j);
}
}
private function drawOnCanvas(index:int):void {
var canvas:CartesianDataCanvas = this["canvas_tentpoles_"+index]; // ← Error likely from here
canvas.lineStyle(1);
canvas.moveTo(10,10);
canvas.lineTo(10,20);
// [...etc...]
}
I'd like to not have to pre-add any more <mx:CartesianDataCanvas>
tags than I'll need, and I'll only need as many as graph_values.length
. Could someone kindly show me where I'm going wrong?