title: accessing GUI-created elements in a class definition file in AS3 (Flash CS4)
body: <p>I've used the GUI to create a rectangle that I turned into a button symbol (SimpleButton). I then edited the button so that it had 4 different button states and a text layer on top. I then created a class definition file for this object so that I could dynamically change the label text (the text layer) when adding instances of this button to the stage.</p>
  
  <p>I was able to create and link a class file (DynamicButton.as) just fine, but when I try to access the text field that I created on the button, I get the error: </p>
  
  <blockquote>
    <p>"Access of possibly undefined property btnLabel through a reference with static type com.examples:DynamicButton."</p>
  </blockquote>
  
  <p>when i couldn't get that to work, I decided I'd try adding the TextField directly within the class definition file, using the following code:</p>
  
  <pre><code>package com.examples 
  {
      import flash.display.Sprite;
      import flash.display.SimpleButton;
      import flash.text.TextField;
  
      public class DynamicButton extends SimpleButton
      {
          public function DynamicButton(btnText:String="Click Me")
          {
              placeText();
              labelText.text = btnText;           
          }
  
          //property variables
              //create a text box to hold the button label
              private var labelText:TextField = new TextField();
              //create a displayObject to hold the text
              private var labelSprite:Sprite = new Sprite();      
  
          private function placeText():void {
              labelText.width = this.width;
              labelText.height = this.height;
              labelText.x = this.x;
              labelText.y = this.y;
              labelText.visible = true;
              labelSprite.addChild(labelText);
              this.parent.addChild(labelSprite);
          }
  
      }
  }
  </code></pre>
  
  <p>The problem is that I can't seem to add the TextField to the SimpleButton, as it's not a display object. So, I tried adding it to the parent of the simple button (and I figured, I'd just place it exactly above the button). But then I get a "null object reference." error.</p>
  
  <p>So, I have two questions</p>
  
  <ol>
  <li>is there a way to access GUI-created elements from w/i a class definition file?</li>
  <li>How would I add the TextField to the button using only AS3 inside of a my class definition file?</li>
  </ol>