When I try, I get an error that the control is not a property of the
app.  For example:
I add a Canvas, and set the ID
  private function addCanvas(oEvent:Event):void
  {
    caNew = new Canvas();
    caNew.id = "canvas1"
    caNew.name = "canvas1";
    caNew.width = 300;
    caNew.height = 100;
    this.addChild(caNew);
  }//  
  
//I try to add a control to the canvas
  private function addControlToCanvas(oEvent:Event):void
  {
    var TextAreaNew:TextArea = new TextArea();
    TextAreaNew.text = "Hello, Other World!"
    //Of course, we can't use the id directly because it does not exist
at compile time, but
    //The next line, using bracket notation on the id of the canvas
still does not find the instance.
    //is the bracket notation getting evaluated at compile-time, that
would explain it.
    this["canvas1"].addChild(TextAreaNew);

    //The following two comment lines show a method that DOES work 
    //var caTemp:Canvas = Canvas(this.getChildByName("canvas1"));
    //caTemp.addChild(TextAreaNew);
  }//  

So is it possible to assign and use an id for a dynamically instantiated
control instance?  Or is getChildByName the best solution?

Tracy

Reply via email to