title: Targeting/accessing hardcoded movieclip in AS3
body: <p>I'm trying to make a block of AS3 code work with an older Flash movie. A movie consisting of ~4000 keyframes and having static movie clips added to main timeline periodically.  </p>
  
  <p>On frame no 120, a movieclip with instance name of <code>playButtonMC</code> is added to stage. <code>playButtonMC</code> has a <code>button</code> instance named <code>playButton</code> inside it. I want to assign click event handler to the button inside this movie clip from main timeline but I'm failing to get a reference to the movie clip from actions on keyframe # 121 on main timeline.  </p>
  
  <p>I've tried following in vain:</p>
  
  <pre><code>var myMc:MovieClip = stage.getChildByName("playButtonMC") as MovieClip;
  trace(myMc);
  trace(playButtonMC);
  trace(root.playButtonMC);
  trace(stage.playButtonMC);
  
  // If I get a reference, I plan to do following to attach event listener.
  // Please advise if its incorrect as well
  myMc.playButton.addEventListener(MouseEvent.CLICK, doStuff);
  
  function doStuff():void{
      trace('called');
  }
  </code></pre>
  
  <p>All calls to <code>trace</code> result in <code>null</code>.</p>
  
  <p>I'm not a Flash developer in any sense but I've been handed over this small task. I know the right AS3 way of doing it must be by dynamically generating the movie clips and storing the references in variables but, at the moment, I'm only trying to make it work somehow.  </p>
  
  <p><strong>EDIT</strong></p>
  
  <p><code>trace(stage.playButtonMC);</code> actually creates an error <code>ReferenceError: Error #1069: Property playButtonMC not found on flash.display.Stage and there is no default value.</code></p>