title: Actionscript 3, addChild from library then access it's children by instance names
body: <p>So I successfully added a movie clip from the library using addChild(), but now I want to access some movieclips that were in that dynamically added movieclip.</p>
  
  <p>I've used standard dot notation and also getChildByName passing it the instance names.</p>
  
  <p>What am I missing here?</p>
  
  <p>---- EDITED ----</p>
  
  <p>I tried the suggestion of looping through and can access them by index, but seems like not as intuitive of a way to do this...  below are the two examples of what I had previously tried and they all come back as "1119: Access of possibly undefined property nameText through a reference with static type flash.display:DisplayObject." or "1061: Call to a possibly undefined method getChildByName through a reference with static type flash.display:DisplayObject."</p>
  
  <p>example of dot notation:</p>
  
  <pre><code> //  build circlular display
  function buildCircle() {
      trace("buildCircle()");
      if (viewByState == "assignment") {
  
          var competencyContainer:MovieClip = new MovieClip();
          competencyContainer.name = "competencyContainer";
          this.addChild(competencyContainer);
  
          var angleSegment:Number = 360 / competenciesArray.length;
          var angleSum:Number = 360 - angleSegment / 2;
  
          for (var i:Number = 0; i &lt; competenciesArray.length; i++) {
  
              var competencyInstance:competencyCircle = new competencyCircle();
              competencyInstance.name = "competency" + i;
              competencyContainer.addChild(competencyInstance);
  
  
              competencyContainer.getChildByName("competency" + i).x = circleCenter.x - (Math.sin(angleSum * (Math.PI / 180)) * (circleSize / 2));
              competencyContainer.getChildByName("competency" + i).y = circleCenter.y - (Math.sin((90 - angleSum) * (Math.PI / 180)) * (circleSize / 2));
  
  
              competencyContainer.getChildByName("competency" + i).nameText.wordWrap = true;
              competencyContainer.getChildByName("competency" + i).nameText.embedFonts = true;
              competencyContainer.getChildByName("competency" + i).nameText.htmlText = "COMPETENCY:&lt;br /&gt;" + competenciesArray[i].name;
  
              competencyContainer.getChildByName("competency" + i).nameText.setTextFormat(tfTitle, 0, competencyContainer.getChildByName("competency" + i).nameText.text.length - competenciesArray[i].name.length);
  
              competencyContainer.getChildByName("competency" + i).nameText.setTextFormat(tfName, competencyContainer.getChildByName("competency" + i).nameText.text.length - competenciesArray[i].name.length, competencyContainer.getChildByName("competency" + i).nameText.text.length);
  
              competencyContainer.getChildByName("competency" + i).nameText.autoSize = TextFieldAutoSize.CENTER;
  
              competencyContainer.getChildByName("competency" + i).nameText.y = -(competencyContainer.getChildByName("competency" + i).nameText.height / 2);
  
              competencyContainer.getChildByName("competency" + i).filters = [circleDefaultDropShadow];
              competencyContainer.getChildByName("competency" + i).selectedIndicator.visible = false;
  
              competencyContainer.getChildByName("competency" + i).hit.buttonMode = true;
              competencyContainer.getChildByName("competency" + i).hit.mouseEnabled = true;
              competencyContainer.getChildByName("competency" + i).hit.tabEnabled = true;
              competencyContainer.getChildByName("competency" + i).hit.mouseChildren = true;
  
              competencyContainer.getChildByName("competency" + i).hit.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
                                                                                       e.target.parent.filters = [circleHoverDropShadow];
                                                                                       });
  
              competencyContainer.getChildByName("competency" + i).hit.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent) {
                                                                                       e.target.parent.filters = [circleDefaultDropShadow];
                                                                                       });
  
              competencyContainer.getChildByName("competency" + i).hit.addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
                                                                                       e.target.parent.filters = [circleDefaultDropShadow];
                                                                                       e.target.parent.selectedIndicator.visible = true;
                                                                                       });
  
              angleSum -= angleSegment;
              trace("end");
              trace(i);
              trace("\n\n\n");
          }
      } else if (viewByState == "competency") {
  
  
  
      } else {
  
      }
  }
  buildCircle();
  </code></pre>
  
  <p>and example using .getChildByName():</p>
  
  <pre><code>    //  build circlular display
    function buildCircle() {
      trace("buildCircle()");
      if (viewByState == "assignment") {
  
          var competencyContainer:MovieClip = new MovieClip();
          competencyContainer.name = "competencyContainer";
          this.addChild(competencyContainer);
  
          var angleSegment:Number = 360 / competenciesArray.length;
          var angleSum:Number = 360 - angleSegment / 2;
  
          for (var i:Number = 0; i &lt; competenciesArray.length; i++) {
  
                  var competencyInstance:competencyCircle = new competencyCircle();
                  competencyInstance.name = "competency" + i;
                  competencyContainer.addChild(competencyInstance);
  
  
                  competencyContainer.getChildByName("competency" + i).x = circleCenter.x - (Math.sin(angleSum * (Math.PI / 180)) * (circleSize / 2));
                  competencyContainer.getChildByName("competency" + i).y = circleCenter.y - (Math.sin((90 - angleSum) * (Math.PI / 180)) * (circleSize / 2));
  
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").wordWrap = true;
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").embedFonts = true;
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").htmlText = "COMPETENCY:&lt;br /&gt;" + competenciesArray[i].name;
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").setTextFormat(tfTitle, 0, competencyContainer.getChildByName("competency" + i).getChildByName("nameText").text.length - competenciesArray[i].name.length);
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").setTextFormat(tfName, competencyContainer.getChildByName("competency" + i).getChildByName("nameText").text.length - competenciesArray[i].name.length, competencyContainer.getChildByName("competency" + i).getChildByName("nameText").text.length);
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").autoSize = TextFieldAutoSize.CENTER;
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("nameText").y = -(competencyContainer.getChildByName("competency" + i).getChildByName("nameText").height / 2);
  
                  competencyContainer.getChildByName("competency" + i).filters = [circleDefaultDropShadow];
                  competencyContainer.getChildByName("competency" + i).getChildByName("selectedIndicator").visible = false;
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").buttonMode = true;
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").mouseEnabled = true;
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").tabEnabled = true;
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").mouseChildren = true;
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
                                                                                                                                                                   e.target.parent.filters = [circleHoverDropShadow];
                                                                                                                                                                   });
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent) {
                                                                                                                                                                   e.target.parent.filters = [circleDefaultDropShadow];
                                                                                                                                                                   });
  
                  competencyContainer.getChildByName("competency" + i).getChildByName("hit").addEventListener(MouseEvent.CLICK, function(e:MouseEvent) {
                                                                                                                                                                   e.target.parent.filters = [circleDefaultDropShadow];
                                                                                                                                                                   e.target.parent.getChildByName("selectedIndicator").visible = true;
                                                                                                                                                                   });
  
                  angleSum -= angleSegment;
                  trace("end");
                  trace(i);
                  trace("\n\n\n");
          }
      } else if (viewByState == "competency") {
  
  
  
      } else {
  
      }
  }
  buildCircle();
  </code></pre>