3 Replies Latest reply on Jan 28, 2008 1:07 PM by buabco

    when does a component get instantiated?

    lw1001
      I'm creating an app that contains a custom component called TaskEditor that is included in the MXML file of another custom component like so:

      .......Snipped.........
      <mx:VDividedBox width="100%" height="100%">
      .......Snipped.........
      <local:TaskEditor id="taskEditor">
      </local:TaskEditor>
      </mx:VDividedBox>
      .......Snipped........
      There's a function called init() defined in the same file that gets invoked on a creationComplete event:

      private function init():void{
      addEventListener("TaskSelectionChangedEvent", taskEditor.taskSelectionChanged); }

      The problem is I'm getting a null pointer exception referring to the taskEditor component. If creation is complete, doesn't that include the creation of the child components in the MXML? Is there a better way to register the childs interests in it's parents events? Thanks.
        • 1. Re: when does a component get instantiated?
          AS3dev
          The null pointer exceptions are sometimes hard to figure out the true target of the problem. It probably isn't that taskEditor isn't created, but something else entirely. Can you provide the full exception text?
          • 2. Re: when does a component get instantiated?
            tinylion_uk Level 2
            are you doing the creation complete on the component or the TaskEditor? I've had this problem once or twice and found that linking it to the sub items will get around this. i know it should have included the child too, but better to have it work than wonder way.

            • 3. Re: when does a component get instantiated?
              buabco Level 1
              Given the small piece of code I can't be certain of this but if you are listening to a creation complete on something that's containing the VDivideBox what might be happening is this:

              The container that has the VDivideBox call the creationComplete event when it's finished creating it's components, but this doesn't necessary mean that the inner components have finished creating their own inner stuff, I suggest you try changing the creation policy an see what happen.