Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reference Flex elements added during runtime?
    primarykey
    data
    text
    <p>This feels like a newbie question, so brace yourself.</p> <p>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: <code>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."]</code>.</p> <pre><code>public function calledAfterInit(graph_values:Array):void { for(var i:int=0; i&lt;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&lt;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...] } </code></pre> <p>I'd like to not have to pre-add any more <code>&lt;mx:CartesianDataCanvas&gt;</code> tags than I'll need, and I'll only need as many as <code>graph_values.length</code>. Could someone kindly show me where I'm going wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload