4 Replies Latest reply on Jun 30, 2010 7:35 AM by PHANTOMIASA

    Component -> access of an id of an element -> null error

    PHANTOMIASA Level 1

      Hello to all!

       

      I have a MyComp.mxml and I create it in my Main.mxml with:

      var myC:MyComp = new MyComp();
      

       

      Content of MyComp.mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <s:SkinnableContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"
                            skinClass="skin.MyBackgroundSkin" width="150" height="70" creationComplete="init()">
      
          <mx:Button id="test" x="0" y="0" label="fff"/>
      ...
      </s:SkinnableContainer>
      

       

      Now I want to add an EventListener on the Button in MyComp.

      I tried it in Main.mxml with:

      myC.test.addEventListener(...);
      

      but I get a null error. Debugging it, shows me that myC.test = null

       

      What's the problem and what can I do to create an EventListener? I do not want to make the EventListener inside the component, because I need data which is avaible in Main.mxml.

       

      Does anyone has an idea?

       

      Thanks a lot in advance for your help!

       

      Best Regards PHANTOMIAS