title: FLEX: the custom component is still a Null Object when I invoke its method
body: <p>I've created a custom component in Flex, and I've created it from the main application with actionscript. Successively I invoke its "setName" method to pass a String.</p>
  
  <p>I get the following run-time error (occurring only if I use the setName method):</p>
  
  <pre><code>TypeError: Error #1009: Cannot access a property or method of a null object reference.
  </code></pre>
  
  <p>I guess I get it because I'm calling to newUser.setName method from main application before the component is completely created.</p>
  
  <p>How can I ask actionscript to "wait" until when the component is created to call the method ? Should I create an event listener in the main application waiting for it ? I would prefer to avoid it if possible.</p>
  
  <p>Here is the code:</p>
  
  <p>Main app</p>
  
  <pre><code>...
  newUser = new userComp();
  //newUser.setName("name");
  </code></pre>
  
  <p>Component:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100" height="200" &gt;
  
  &lt;mx:Script&gt;
      &lt;![CDATA[
  
  
          public function setName(name:String):void {
              username.text = name;
          }
  
         public function setTags(Tags:String):void {
  
          }
  
      ]]&gt;
      &lt;/mx:Script&gt;
  
      &lt;mx:HBox id="tagsPopup" visible="false"&gt;
          &lt;mx:LinkButton label="Tag1" /&gt;
          &lt;mx:LinkButton label="Tag2" /&gt;
          &lt;mx:LinkButton label="Tag3" /&gt;      
      &lt;/mx:HBox&gt;
  
      &lt;mx:Image source="@Embed(source='../icons/userIcon.png')"/&gt;
      &lt;mx:Label id="username" text="Nickname" visible="false"/&gt;
  
  &lt;/mx:VBox&gt;
  </code></pre>
  
  <p>thanks</p>